要解决此问题,请使用以下代码行:
long childrenCount = snapshot.getChildrenCount();int count = (int) childrenCount;int randomNumber = new Random().nextInt(count);
然后使用
for循环使用随机数提取该值:
int i=0;String themeTune; //Your random themeTune will be stored herefor (DataSnapshot snap : snapshot.getChildren()) { if(i = randomNumber) { themeTune = snap.getValue(String.class); break; } i++;}plysound();


