从Firebase Android中的不同节点向同一列表添加值

从Firebase Android中的不同节点向同一列表添加值,android,list,firebase,firebase-realtime-database,Android,List,Firebase,Firebase Realtime Database,我有以下Firebase数据库结构 "Aspirant" : { "Laikipia County" : { "Senators" : { "Esir Makau" : { "aspirantCounty" : "Laikipia County", "aspirantDocket" : "Senators", "aspirantName" : "Esir Makau", "asp

我有以下Firebase数据库结构

 "Aspirant" : {
    "Laikipia County" : {
      "Senators" : {
        "Esir Makau" : {
          "aspirantCounty" : "Laikipia County",
          "aspirantDocket" : "Senators",
          "aspirantName" : "Esir Makau",
          "aspirant_twitter_handle" : "esir",
          "currentVotes" : 62,
          "thumbnail" : "dd",
          "votes" : {
            "111" : true,
            "358110075338850" : true
          },
          "votesCount" : 0
        },
        "JoMueke" : {
          "aspirantCounty" : "Laikipia County",
          "aspirantDocket" : "Senators",
          "aspirantName" : "JoMueke",
          "aspirant_twitter_handle" : "jmueke",
          "currentVotes" : 344,
          "thumbnail" : "trued",
          "votes" : {
            "111" : true
          },
          "votesCount" : 0
        },
        "Mionko" : {
          "aspirantCounty" : "Laikipia County",
          "aspirantDocket" : "Senators",
          "aspirantName" : "Mionko",
          "aspirant_twitter_handle" : "MikeSonko",
          "currentVotes" : 6620,
          "thumbnail" : "http://venasnews.co.ke/wp-content/uploads/2016/10/mike-sonko.jpg",
          "votes" : {
            "111" : true
          },
          "votesCount" : 0
        }
      }
    },
    "Nairobi County" : {
      "Senators" : {
        "Jonathan Mueke" : {
          "aspirantCounty" : "Nairobi County",
          "aspirantDocket" : "Senators",
          "aspirantName" : "Jonathan Mueke",
          "aspirant_twitter_handle" : "jmueke",
          "currentVotes" : 3462,
          "thumbnail" : "trued",
          "votes" : {
            "22" : true,
            "358110075338850" : true
          },
          "votesCount" : 0
        },
        "Mike Sonko" : {
          "aspirantCounty" : "Nairobi County",
          "aspirantDocket" : "Senators",
          "aspirantName" : "Mike Sonko",
          "aspirant_twitter_handle" : "MikeSonko",
          "currentVotes" : 6622,
          "thumbnail" : "http://venasnews.co.ke/wp-content/uploads/2016/10/mike-sonko.jpg",
          "votes" : {
            "22" : true
          },
          "votesCount" : 0
        }
      }
    }
  },
  "Aspirants" : {
    "Presidents" : {
      "Musalia Mudavadi" : {
        "aspirantCounty" : "Kenya County",
        "aspirantDocket" : "Presidents",
        "aspirantName" : "Musalia Mudavadi",
        "aspirant_twitter_handle" : "MusaliaMudavadi",
        "currentVotes" : 1220,
        "thumbnail" : "http",
        "votes" : {
          "111" : true
        },
        "votesCount" : 0
      },
      "Raila Odinga" : {
        "aspirantCounty" : "Kenya County",
        "aspirantDocket" : "Presidents",
        "aspirantName" : "Raila Odinga",
        "aspirant_twitter_handle" : "RailaOdinga",
        "currentVotes" : 1047,
        "thumbnail" : "http://www.somalilandpress.com/wp-content/uploads/2016/07/raila.jpg",
        "votes" : {
          "111" : true,
          "358110075338850" : true
        },
        "votesCount" : 0
      },
      "Uhuru Kenyatta" : {
        "aspirantCounty" : "Kenya County",
        "aspirantDocket" : "Presidents",
        "aspirantName" : "Uhuru Kenyatta",
        "aspirant_twitter_handle" : "UKenyatta",
        "currentVotes" : 1043,
        "thumbnail" : "http://hashtagsquare.co.ke/wp-content/uploads/2010/08/uhuru-kenyatta-biography.jpg",
        "votes" : {
          "111" : true
        },
        "votesCount" : 0
      }
    }
  }
我要读取的两个数据库节点是

availableAspirantsPresidents=FirebaseDatabase.getInstance().getReference().child("Aspirants").child("Presidents");
availableAspirants= FirebaseDatabase.getInstance().getReference().child("Aspirant").child(Counties[county]);
然后我有一个清单

final ArrayList<Aspirant>commonPresidentsAndSpecificAspirants=new ArrayList<>();
如何将
AvailablesPirantsPresidents
的内容添加到
CommonPresident和SpecificAspirants
中,始终作为第一个元素。 我尝试嵌套
可用的SpirantsPresidents
侦听器,但它不起作用。
非常感谢您的帮助。

您所说的“第一要素”是什么意思?这就像将值添加到数组的第一个元素,还是将
ArrayList
Map
之类的东西混淆,其中第一个元素是键,第二个元素是值?我的意思是
AvailablesPirantsPresidents
中的
Aspirants
对象始终位于
CommonPresidents和SpecificAspirants
数组中如何:首先将
AvailablesPirantsPresidents
中的所有值放入
CommonPresidents和SpecificAspirants
。然后执行上面提到的代码,以更新
CommonPresident和SpecificAspirators
(如果有值)
availableAspirants.addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                for(DataSnapshot dss:dataSnapshot.getChildren()){
                    Log.e("Key :",""+dss.getKey());//Prints eg. Senators,Governors etc
                    if(dss.getChildrenCount()>0){
                        //I want Even if dss.getChildrenCount=0 Still add a Pressident in the List
                        ArrayList<BarEntry>entries=new ArrayList<>();
                        for(int i=0;i<dss.getChildrenCount();i++){//Real Asp
                            Aspirant aspirant;
                            for (DataSnapshot fd:dss.getChildren()){
                                aspirant=fd.getValue(Aspirant.class);
                                commonPresidentsAndSpecificAspirants.add(aspirant);
                            }
                            if(commonPresidentsAndSpecificAspirants.size()>0){                                 
                                entries.add(new BarEntry(i, (float) (commonPresidentsAndSpecificAspirants.get(i).getCurrentVotes())));
                            }
                        }
                    }else{

                }
            }