Reputation: 83
How can I get random key from Firebase realtime database that are stored in list?
Upvotes: 0
Views: 3136
Reputation: 80914
Try this:
DatabaseReference reference = FirebaseDatabase.getInstance().getReference("inspirational");
reference.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot datas: dataSnapshot.getChildren()){
String keys=datas.getKey();
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
First you need to go the dataSnapshot inspirational
, then iterate inside of it and, this will give you the random keys String keys=datas.getKey();
Upvotes: 5