Trịnh Minh
Trịnh Minh

Reputation: 255

How I can select data from Firebase Database with data in level 3 on Android?

How I can select key of “Notifications” with value “Show Again” if true?

This is my query but it’s not working.

String startAtKey = "order_trinhvanminh2009@gmail,com";
//Query to get the notification in orders is allow showing.
Query queryNotification = dataNotification.orderByChild("order")
                             .startAt(true, startAtKey).endAt(true, startAtKey).orderByChild("Notifications")
                             .orderByChild("Show Again").equalTo(true);

Here’s my database structure:

enter image description here

Upvotes: 1

Views: 578

Answers (1)

Atif AbbAsi
Atif AbbAsi

Reputation: 6035

All you have to do is access child of object like this.!

   mdatabaseRef.child("order").child("order_trinhvanminh2009@gmail,com_12").child("Notifications").child("order_order_trinhvanminh2009@gmail,com_12_notification_0").orderByChild("Show Again").equals("true").addValueEventListener(new ValueEventListener() {
                @Override     
                public void onDataChange(DataSnapshot dataSnapshot) {
                     String value = (String) dataSnapshot.getValue();
                    }

all you have to do is nested query

 dataSnapshot.getChildren(); 

    mdatabaseRef.child("order").child(dataSnapshot.getChildren()).



     mdatabaseRef.child("order").addValueEventListener(new ValueEventListener() {
  @Override     
  public void onDataChange(DataSnapshot dataSnapshot) {
     for (DataSnapshot child: dataSnapshot.getChildren()){
        String key = child.getKey();
         fun(key);
         }

  private void fun(String key){

    mdatabaseRef.child("order").child(key).addValueEventListener(new ValueEventListener() {
   @Override     
   public void onDataChange(DataSnapshot dataSnapshot) {for (DataSnapshot child: dataSnapshot.getChildren()){
  String key = child.getKey();
   fun(key);
 }

    }

Upvotes: 1

Related Questions