Search code examples
androidfirebasefirebase-realtime-databasefirebase-authenticationfirebaseui

Firebase Android : How to get list inside specific child?


I'm trying to retrieve inner list of specific child. Please refer following structure.

If I want to retrieve "servicesArrayList" for "recipient" where "billNo" is "135", What query I should be writing so that I can pass that query to FirebaseRecyclerAdapter (firebase -ui)

FirebaseRecyclerAdapter is for servicesArrayList for specific recipient.

    FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
    String uid = user.getUid();

    Query query = FirebaseDatabase.getInstance()
            .getReference(RECIPIENT_NODE)
            .child(uid)
            .child("servicesArrayList")
            .orderByChild ?




recipient // parent Node

 2R1Q8qKEPHXFU1OiMq5TyxHBaZa2 // uId

   -KgJhMAWADwownv5tck6  // push Id
   -KgJhMAWADwownv5tck6
   -KgJoD77HQK-yACD_EuB
   -KgJoRXVUP_-Z0gLhIWy
   -KgJob82t47PvTjfTtig
   -KgK-N_Av_2kmmQS0Ulx

   -KgNu-fVWwFDLnRENj_b // Recipient Data
        billNo: 135
        billingMonth: "July 2017"
        childGender: "Ms."
        childName: "xyz"
        date: "29/03/2017"
        fineAmount: 0
        paymentStatus: "UNPAID"
        pushId: "-KgNu-fVWwFDLnRENj_b"
        receiptUrl:"https://firebasestorage.googleapis.com/v0/b/ngf..."
        recipientEmail: "abc@gmail.com"
        recipientName: "Abc C."
        servicesArrayList
                 -0
                    -amount: 1000
                    -charges: "1000"
                    -noOfSessions: 1
                    -serviceType: "Speech And Language Assessment"

        total: 1000
        vat: 0

Solution

  • If you knnow the uid and the push id, then this should do it:

    Query query = FirebaseDatabase.getInstance().getReference(RECIPIENT_NODE)
        .​child(uid).child(pus‌​hId).child("services‌​ArrayList");
    

    Hope this helps