Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Filterable #511

Open
ahmednabeel1991 opened this issue Oct 13, 2020 · 0 comments
Open

Implement Filterable #511

ahmednabeel1991 opened this issue Oct 13, 2020 · 0 comments

Comments

@ahmednabeel1991
Copy link

Hello There,
I am using this library which is really helpful, but I am stuck on one thing. How to implement Search functionality in this library.

Right now I am trying and it is not giving me correct position when filterable is active other than this it is giving correct

Filter code is here bwllow

` @OverRide
public Filter getFilter() {
return new Filter() {
@SuppressWarnings("unchecked")
@OverRide
protected void publishResults(CharSequence constraint, FilterResults results) {
dummyList = (List) results.values;
notifyDataSetChanged();
}

        @Override
        protected FilterResults performFiltering(CharSequence constraint) {
            List<GetByModel> filteredResults = null;
            if (constraint.length() == 0) {
                filtered = groupList;
                filteredResults = groupList;
            } else {
                filteredResults = getFilteredResults(constraint.toString().toLowerCase());
            }

            FilterResults results = new FilterResults();
            results.values = filteredResults;

            return results;
        }
    };
}

protected List<GetByModel> getFilteredResults(String constraint) {
    List<GetByModel> results = new ArrayList<>();
    for (GetByModel item : dummyList) {
        for (GenericModelFilterSelection genericModelFilterSelection : item.getGenericModels()) {
            if (genericModelFilterSelection.getName().toLowerCase().contains(constraint)) {
                if (!results.contains(item)) {
                    results.add(item);
                }
            }
        }
    }
    return results;
}

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant