To simplify my problem: I have a Firebase database that has a "businesses" node and the businesses node has children with ID's and corresponding data about that particular business. I do not want to show all of the businesses in my firebase Recycler View, only certain ones. For the ones I want to show at any give time, I have a list of IDs.
...
List<String> businessList = ("00002", "00004", "00021");
...
private void setUpFirebaseAdapter() {
mFirebaseAdapter = new FirebaseRecyclerAdapter<User, FirebaseBusinessViewHolder>
(User.class, R.layout.business_list_item, FirebaseBusinessViewHolder.class, mBusinessReference{
@Override
protected void populateViewHolder(FirebaseBusinessViewHolder viewHolder, User model, int position){
for (String businessID : businessList) {
if (businessID.equals(model.getId())){
//show this item
viewHolder.bindBusiness(model, true);
}
if(!businessID.equals(model.getId())){
//don't show this item
}
}
}
};
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
mRecyclerView.setAdapter(mFirebaseAdapter);
}
If I run this code, it will only show the data from the businessList, but it also leaves an empty space for the other items stored in the database whose ID was not on the businessList, as it creates the empty list item but does not bind any data to it. I obviously don't want the gap/empty space to show up for unwanted items. How can I adjust my list adapter/view holder to only show the desired items?