问题
Taking reference from FireChat app I used FirebaseRecyclerAdapter in my app, it is working fine but I need to filter data which equals to specific user ID.
In populateView if I does that data is getting filtered but a blank recycler Item item is also getting created.
mFirebaseAdapter = new FirebaseRecyclerAdapter<Tags, TagsViewHolder>(
Tags.class,
R.layout.item_message,
TagsViewHolder.class,
mFirebaseDatabaseReference.child("tags")) {
@Override
protected void populateViewHolder(TagsViewHolder viewHolder, Tags tags, int position) {
mProgressBar.setVisibility(ProgressBar.INVISIBLE);
if((tags.getUserid()).equals(mFirebaseUser.getUid()))
viewHolder.tagTextView.setText(tags.getTagname());
}
};
Is there any way I can filter it before a view gets created?
my POJO class is:
public class Tags {
private String userid;
private String tagname;
private HashMap<String, Object> timestampCreated;
public Tags() {
}
public Tags(String userid, String tagname, HashMap<String, Object> timestampCreated) {
this.userid = userid;
this.tagname = tagname;
this.timestampCreated = timestampCreated;
}
public String getUserid() {
return userid;
}
public String getTagname() {
return tagname;
}
public HashMap<String, Object> getTimestampCreated() {
return timestampCreated;
}
}
Thank you!
回答1:
Client-side filtering is an open feature request for FirebaseUI. See https://github.com/firebase/FirebaseUI-Android/issues/15.
Client-side filtering of data, means that the app first download data and then doesn't show it to the user. This is wasteful and most users of mobile apps will appreciate it if your app only downloads data that it shows to them.
The best ways to deal with displaying a subset of the data is to either model the data in a way so that you can directly access the subset of data that you want to display, or to use Firebase queries to limit the data that is retrieved.
来源:https://stackoverflow.com/questions/39076702/filtering-data-before-populating-view-from-firebaserecycleradapter