如何在Firebase Android中检索数组的数组列表?

时间:2017-03-01 12:56:08

标签: android firebase firebase-realtime-database

这是图片:

Here's the Image

如何检索custProd的内容?提前谢谢。

1 个答案:

答案 0 :(得分:1)

        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 + "");
        }
 });