I dont like to show empty RecyclerView to users. I know there is getItemCount method in recyclerview, but i think reyclerview is executed on separate thread maybe. Its because w
You can use ValueEventListener
to check if any values exists:
DatabaseReference ref = FirebaseDatabase.getInstance().getReference().child("Users");
Query queries = ref.orderByChild("name").equalTo(name_here);
queries.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.exists()) {
Toast.makeText(HomeActivity.this,"data exists",Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(HomeActivity.this,"No data exists",Toast.LENGTH_SHORT).show();
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
In your Adapter, you need to use a query to be able to get the data, example as the above query and it will also check if the data exists.
Then you can configure the adapter by building FirebaseRecyclerOptions
:
FirebaseRecyclerOptions<FriendsModel> friendsOptions =
new FirebaseRecyclerOptions.Builder<FriendsModel>()
.setQuery(queries, FriendsModel.class)
.build();
Simply override onDataChanged
and check for getItemCount()
there.