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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…