I'm creating a project, that uses a webservice to fetch the number of departments and there names and creates dynamic checkboxs. Then I'm using filterable to filter the adapter , by checking from sharedpreferences if the checkbox is checked if not checked I try to hide it from the adapter (TicketsActivity):
for (int i=0;i<filterList.size();i++) {
if (!getFromSP(filterList.get(i) + i)) {
mAdapter.getFilter("Department").filter(filterList.get(i).toLowerCase());
}
}
and afther that
if (recyclerView.getAdapter() == null) {
mAdapter.notifyItemRangeInserted(0,ticketList.size()-1);
recyclerView.setAdapter(mAdapter);
} else {
recyclerView.getAdapter().notifyItemRangeInserted(0,ticketList.size()-1);
}
And in my custom Adapter (TicketsAdapter):
public Filter getFilter(final String type) {
return new Filter() {
@Override
protected FilterResults performFiltering(CharSequence charSequence) {
String charString = charSequence.toString();
if (charString.isEmpty()) {
ticketListFiltered = ticketList;
} else if (type.equals("Search")) {
List<Ticket> filteredList = new ArrayList<>();
for (Ticket row : ticketList) {
if (row.getTitle().toLowerCase().contains(charSequence) || row.getDate().toLowerCase().contains(charSequence) || row.getPriority().toLowerCase().contains(charSequence)) {
filteredList.add(row);
}
}
ticketListFiltered = filteredList;
} else {
List<Ticket> filteredList;
filteredList = ticketList;
for (Ticket row : ticketList) {
if (row.getDepartment().toLowerCase().contains(charSequence)) {
filteredList.remove(row);
}
}
ticketListFiltered = filteredList;
}
FilterResults filterResults = new FilterResults();
filterResults.values =ticketListFiltered;
return filterResults;
}
@Override
public int getItemCount() {
return ticketListFiltered.size();
}
However this throws an Exception on 'int java.util.List.size()' getItemCount, if i change the filteredList.remove(row) to filteredList.add(row) it will work find,but i need to remove from the adapter rows with "unchecked" department. I can't find what i'm doing wrong. Btw this works fine with SearchView
Aucun commentaire:
Enregistrer un commentaire