Java – Get specific categories of data from firebase

Get specific categories of data from firebase… here is a solution to the problem.

Get specific categories of data from firebase


want to categorize the data in the Firebase live database and then select them by category to display in different parts of my android View, but I don’t know where to start. I’m new to Firebase, I just know how to extract data, push it to the Firebase database, and display all the acquired data.

My question is: is this possible? If so, what should I do?


If you have this database:

       name: dog
       category: mammal
       name: snake
       category: reptile
       name: elephants
       category: mammal

You can then query by class:

DatabaseReference ref=FirebaseDatabase.getInstance().getReference("Animals");
Query query=ref.orderByChild("category").equalTo("mammal");

query.addListenerForSingleValueEvent(new ValueEventListener() {
public void onDataChange(DataSnapshot dataSnapshot) {
  for(DataSnapshot datas: dataSnapshot.getChildren()){
     String name=datas.child("name").getValue().toString();
public void onCancelled(DatabaseError databaseError) {

This will retrieve all names with categories equal to mammals.

Check here too:

Related Problems and Solutions