Tonvince G. Tonvince G. -4 years ago 281
Android Question

How to retrieve an array list of data in Firebase Android?

Here's the Image:

Here's the Image

How do I retrieve the contents of

custProd
? Thanks in advance.

Answer Source
        Firebase.setAndroidContext(this);
        Firebase ref = new Firebase(YOUR_FIREBASE_URL); 

        ArrayList custProd= new ArrayList<>();

        ref.child("customerrequest/-Ke8u4..../custProd/")
                  .addListenerForSingleValueEvent(new ValueEventListener() {
                   @Override
                   public void onDataChange(DataSnapshot dataSnapshot) {

                   try {
                        if (dataSnapshot.getValue() != null) {
                         Map<String, String> value = (Map<String, String>) dataSnapshot.getValue();
                       for (Map.Entry<String, String> entry : value.entrySet())
                       {
                        String _key = entry.getKey();
                        String _value = entry.getValue();
                        // TODO add value in list
                        if (_value.length() > 0 && !custProd.contains(_value))
                                    custProd.add(_value);
                          Log.e("!__@::>", _key + " " + _value);
                         }
                  }
                } catch (Exception e) {
                     e.printStackTrace();
             }
        }
      @Override
  public void onCancelled(FirebaseError firebaseError) {
              Log.e("!_@@@_@@_GetAllcustProd:>", firebaseError + "");
        }
 });
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download