Android – firebase searches by character
•
Android
I use firebaserecycleradapter in my firebase application. Until now, I don't know how to search firebase by character. I have used query, but I get a good result, but it is not available. Here is the database search I want:
This is my method. I use it, but if I only enter the full name, it gets "user name", so if I write "m", it does not display:
mMainSearcher.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
Query Q = mDatabase.child("Users").orderByChild("Username").equalTo(newText);
FirebaseRecyclerAdapter<Getting_Friends, Search.SearchViewHolder> firebaseRecyclerAdapter22 = new FirebaseRecyclerAdapter<Getting_Friends, Search.SearchViewHolder>(
Getting_Friends.class, R.layout.my_friends_card, Search.SearchViewHolder.class, Q) {
@Override
protected void populateViewHolder(final Search.SearchViewHolder viewHolder, final Getting_Friends model, int position) {
viewHolder.setUsername(model.getUsername());
viewHolder.setProfile(getApplicationContext(), model.getProfile());
}
};
mFriendsRecyclerView.setAdapter(firebaseRecyclerAdapter22);
return false;
}
});
This is what I get when I enter my full name:
This is the result when I write "m" or "m":
So I just need > > when I write "m" automatically, all user names starting with "m" must be displayed as Mike
resolvent:
Try this
Query Q = mDatabase.child("Users").orderByChild("Username").startAt(newText).endAt("~");
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码