Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
341 views
in Technique[技术] by (71.8m points)

nodes - Get multiple keys from firebase realtime database

I'm trying to retrieve data from the firebase real-time database. In the parent node, I have five child nodes. I want to get all the node names from the parent node and set the value to a textView. I've tried the getkey() method but it returns only one key. How to retrieve multiple child nodes from firebase?

ref.orderByKey().addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(@NonNull DataSnapshot snapshot) {
                if (snapshot.exists() && !snapshot.equals(null))
                {
                    for (DataSnapshot ds: snapshot.getChildren()){
                        String key = ds.getRef().getKey();

                            holder.regionTV.setText(key);

                            holder.myLayoutLayout.setVisibility(View.VISIBLE);
                            holder.region_Count = (int) ds.getChildrenCount();
                            holder.regionCountTV.setText(Integer.toString(holder.region_Count));

                    }


                }
                else
                {
                    holder.regionCountTV.setText("0");
                    holder.myLayoutLayout.setVisibility(View.GONE);
                }





            }

            @Override
            public void onCancelled(@NonNull DatabaseError error) {

            }
        });
question from:https://stackoverflow.com/questions/66049511/get-multiple-keys-from-firebase-realtime-database

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...