I'm trying to sort the values in my recyclerview by using a spinner. Can anyone help me with sorting this out? I'm specifically trying to organize the food by appetizer and treats, mains, and horse d'eourves. I would love to separate the item once one of the items on the spinner is selected. Your help will be greatly appreciated :)
Here is my code for the spinner:
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
switch (position) {
case 1:
case 2:
case 3:
break;
}
}
CodePudding user response:
I am using SearchView filter in RecyclerView ,I Hope this Code Will Help You
searchview:
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
// inside on query text change method we are
// calling a method to filter our recycler view.
filter(newText);
return false;
}
});
Filter method
private EmployeeReportAdapter adapter;
private List<EmployeeDetails_Response> courseModalArrayList;
EmployeeDetails_Response is my model class
:
private void filter(String text) {
try {
// creating a new array list to filter our data.
ArrayList<EmployeeDetails_Response> filteredlist = new ArrayList<>();
// running a for loop to compare elements.
for (EmployeeDetails_Response item : courseModalArrayList) {
// checking if the entered string matched with any item of our recycler view.
if (item.getEmployeeCode().toLowerCase().contains(text.toLowerCase())) {
// if the item is matched we are
// adding it to our filtered list.
filteredlist.add(item);
}
}
if (filteredlist.isEmpty()) {
// if no item is added in filtered list we are
// displaying a toast message as no data found.
Toast.makeText(this, "No Data Found..", Toast.LENGTH_SHORT).show();
} else {
// at last we are passing that filtered
// list to our adapter class.
adapter.filterList(filteredlist);
}
}catch (Exception e){
}
}
in adapter:
public void filterList(ArrayList<EmployeeDetails_Response> filterllist) {
try {
// below line is to add our filtered
// list in our course array list.
employeeDetailsRespons = filterllist;
// below line is to notify our adapter
// as change in recycler view data.
notifyDataSetChanged();
}catch (Exception e){
}
}
CodePudding user response:
Sort the ArrayList
and it'll appear sorted in the RecyclerView
employeeDetailsRespons = filterllist.sort();