如何从Firebase Android获取所有子列表

我想要Android中Firebase的所有子列表。


我已经实现了此代码,但无法正常工作。


mFirebaseRef = new Firebase(FIREBASE_URL);


mFirebaseRef.addValueEventListener(new ValueEventListener() {

    @Override

    public void onDataChange(DataSnapshot dataSnapshot) {

        List<String> td = (ArrayList<String>) dataSnapshot.getValue();

        //notifyDataSetChanged();

    }


    @Override

    public void onCancelled(FirebaseError firebaseError) {


    }

});


慕侠2389804
浏览 541回答 3
3回答

斯蒂芬大帝

FirebaseDatabase mFirebaseDatabase = FirebaseDatabase.getInstance();&nbsp;DatabaseReference databaseReference =&nbsp; &nbsp; mFirebaseDatabase.getReference(FIREBASE_URL);&nbsp; &nbsp; &nbsp; &nbsp; databaseReference.addValueEventListener(new ValueEventListener() {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @Override&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public void onDataChange(DataSnapshot dataSnapshot) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (DataSnapshot childDataSnapshot : dataSnapshot.getChildren()) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Log.v(TAG,""+ childDataSnapshot.getKey()); //displays the key for the node&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Log.v(TAG,""+ childDataSnapshot.child(--ENTER THE KEY NAME eg. firstname or email etc.--).getValue());&nbsp; &nbsp;//gives the value for given keyname&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; @Override&nbsp; &nbsp; &nbsp; &nbsp; public void onCancelled(DatabaseError databaseError) {&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; });希望能帮助到你!
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Android