Open hackaprende opened 7 years ago
@Almaral-Engineering This isn't something that is implemented by the library, but can be done outside the adapter just like any RecyclerView Adapter.
Apply your filter to the list of Parent/Child objects, you'll now have a reduced list. Update the list on the adapter, and call the individual notify methods. OR call the less efficient notifyParentDataSetChanged
/setParentList
methods on the adapter to just tell the adapter to refresh everything.
Thanks @paul-turner!, I did it with the setParentList and it works now! For others who see this thread, I did this:
private final class ChildObjectFilter extends Filter {
@Override
protected FilterResults performFiltering(final CharSequence constraint) {
final String filterString = constraint.toString().toLowerCase();
final FilterResults results = new FilterResults();
final ArrayList<ParentObject> filteredParentObjects = new ArrayList<>();
for (ExpandableWrapper<ParentObject, ChildObject> expandableWrapper : listToFilter) {
final ArrayList<ChildObject> filteredChildObjects = new ArrayList<>();
final ParentObject ParentObject = expandableWrapper.getParent();
for (final ChildObject ChildObject : ParentObject.getChildObjectList()) {
if (ChildObject.getName().toLowerCase().contains(filterString)) {
filteredChildObjects.add(ChildObject);
}
}
if (filteredChildObjects.size() > 0) {
final ParentObject filteredParentObject =
new ParentObject(ParentObject.getId(), ParentObject.getDescription(),
ParentObject.getEnabled(), filteredChildObjects);
filteredParentObjects.add(filteredParentObject);
}
}
results.values = filteredParentObjects;
results.count = filteredParentObjects.size();
return results;
}
@SuppressWarnings("unchecked")
@Override
protected void publishResults(final CharSequence constraint, final FilterResults results) {
final ArrayList<ParentObject> ParentObjectFilteredList =
(ArrayList<ParentObject>) results.values;
setParentList(ParentObjectFilteredList, true);
}
}
Awesome, thanks for following through with the solution :)
Whats that listToFilter value?
Hi, is it possible to filter results with this library? what would be a possible implementation?