I am using the FirebaseRecyclerAdapter of Firebase-UI. I'm not able to implement the filter in SearchView.
My database:
My Question:
How to search in FirebaseDatabase by character using FirebaseRecyclerAdapter ?
(I want to search by username)
My Code: I used this method for search, what's wrong in my code?
mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
Query Q = mAllUsersDatabaseRef.child("User").orderByChild("username").startAt(newText).endAt("~");
FirebaseRecyclerAdapter<User, SearchFeedFragment.AllRegisterUserViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<User, SearchFeedFragment.AllRegisterUserViewHolder>(
User.class, R.layout.row_search_all_users, SearchFeedFragment.AllRegisterUserViewHolder.class, Q) {
@Override
protected void populateViewHolder( SearchFeedFragment.AllRegisterUserViewHolder viewHolder,User model, int position) {
viewHolder.setUserName(model.getUsername());
viewHolder.setUserProfilePic(Common.stringToBitMap(model.getProfilepicurl()));
}
};
mRecyclerViewSearch.setAdapter(firebaseRecyclerAdapter);
return false;
}
});
public static class AllRegisterUserViewHolder extends RecyclerView.ViewHolder {
View mView;
ImageView mImgProfileImage = (ImageView) itemView.findViewById(R.id.iv_searchProfilePic);
TextView mTxtProfileName = (TextView) itemView.findViewById(R.id.txt_searchProfileName);
public AllRegisterUserViewHolder(View itemView) {
super(itemView);
itemView = mView;
}
public void setUserName(String username) {
mTxtProfileName.setText(username);
}
public void setUserProfilePic(Bitmap image) {
mImgProfileImage.setImageBitmap(image);
}
}