Filtering recirculation using firebaserecycleradapter

I have a RecyclerView with FirebaseRecyclerAdapter. I want to populate RecyclerView with a list of names when the user starts typing in SearchView.

public class SchoolsAdapter extends FirebaseRecyclerAdapter<School, SchoolsAdapter.SchoolViewHolder> {

    public SchoolsAdapter(Query ref) {
        super(School.class, R.layout.item_school, SchoolViewHolder.class, ref);
    }

    @Override
    public void populateViewHolder(SchoolViewHolder schoolViewHolder, School school, int position) {
        schoolViewHolder.name.setText(school.getName());
        schoolViewHolder.address.setText(school.getAddress());
    }

    static class SchoolViewHolder extends RecyclerView.ViewHolder {

        public TextView name;
        public TextView address;

        public SchoolViewHolder(View itemView) {
            super(itemView);
            name = (TextView) itemView.findViewById(R.id.school_item_tview_name);
            address = (TextView) itemView.findViewById(R.id.school_item_tview_address);
        }
    }
}

I assume that I need to add a QueryTextListener to the searchview, which will update the query in the adapter. Does it break FirebaseRecyclerAdapter?

Or should I

@Override
public boolean onQueryTextChange(String newText) {
    mRecyclerView.setAdapter(new SchoolAdapter(ref.orderByChild("name").startAt(userQuery).endAt(userQuery+"~")) 
    return false;
}

whenever a user enters something?

The docs also talk about organizing and sorting firebase requests, but they clearly don't say the best way to perform string matching. What is the best way to perform string matching so that the recycler view displays all the results that have the search query as a substring of the database record, and possibly those that are also edited from a distance.

?

+4
1

- , , , , , , , .

-, FirebaseAdapter, mFullList, mItems FirebaseAdapter , , . , mFullList Firebase, , , super.X() .

:

public reset(List)
   mFullList = List
   Collections.sort(mFullList, Comparator)
   getFilter().filter(filterString)

String - getFilter(). filter(). mFullList :

mFullList.get(pos).getName().toLowerCase().contains(filterString.toLowerCase);

, Filter.publishResults FilterResults. publishResults , .

filterCompleted(List)
   getItems().clear
   getItems().addAll
   notify

, , FirebaseAdapater , , . , , .

, :

adapter.getFilter().filter("something")

adapter.getFilter().filter("")

to reset ( , doneFilter() . , FireBase , , t Firebase.

+3

Source: https://habr.com/ru/post/1620999/


All Articles