I'm trying to understand groups in Firebase database. I've created a simple index called "genres" which I've placed inside my stations node:
"STATIONS": {
"GENRES": {
"D&B": {
"RODR": false
},
"HipHop": {
"RODR": false
},
"TRANCE": {
"RODR": true
}
},
"RODR": {
"PROMOTED": false,
"downvote": 2,
"image": "image url",
"station": "Revolution Of Dance Radio",
"tag": "We Are The Revolution",
"upvote": 1001,
"url": "to be added"
},
"UKNRADIO": {
"Promoted": false,
"downvote": 2,
"image": "url for image",
"station": "UKN RADIO",
"tag": "The Home Of The Mashup",
"upvote": 1001,
"url": "to add"
}
},
Then I have these children in a separate node with the key set to the same as the index key.
How do I query the genre node to get all items in the trance index? Which in this example would be RODR?
Edit
This value is to gain access to the right child with in my Genres node:
String value = getArguments().getString("Genre");
Log.i("Genre_bundle",value);
This is the basic code for showing my list:
String DATABASE_CHILD = "STATIONS";
ref = db.getReference().child(DATABASE_CHILD);
Edit 2
I've tried setting up the query in a separate listener to get the key I need; this works, but only if there's a single item in the node. As soon as I add a second, for example uknradio= true it won't show.
String DATABASE_CHILD = "STATIONS";
ref = db.getReference().child(DATABASE_CHILD).child("GENRES").child(value);
Query query = ref.orderByValue().equalTo(true);
query.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
for (DataSnapshot dataSnapshot: snapshot.getChildren())
KEYS = dataSnapshot.getKey();
Log.i("KEY", KEYS);
getStations(KEYS);
}
private void getStations(String Key) {
String DATABASE_CHILD = "STATIONS";
ref1 = db.getReference().child(DATABASE_CHILD);
ref1.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
for (DataSnapshot snap : snapshot.getChildren()) {
String key_Checker = snap.getKey();
if (KEYS.matches(key_Checker)) {
Log.i("KEY", "Present");