I have a firebase database with a tree that looks like this
tvthemetunes
airwolf value \"url to air wolftheme\"
eastenders value \"url to eastenders\"
knigh
To solve this, please use the following lines of code:
long childrenCount = snapshot.getChildrenCount();
int count = (int) childrenCount;
int randomNumber = new Random().nextInt(count);
And then use a for
loop to pull that value using the random number:
int i=0;
String themeTune; //Your random themeTune will be stored here
for (DataSnapshot snap : snapshot.getChildren()) {
if(i = randomNumber) {
themeTune = snap.getValue(String.class);
break;
}
i++;
}
plysound();