-3
final int[] ndomande = {14};
//Database
mFirebaseInstance = FirebaseDatabase.getInstance();
final DatabaseReference Refndom = mFirebaseInstance.getReference("Dati");
final Query queryn = Refndom.orderByChild("numero_domande");
queryn.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
//Toast.makeText(PlayTest.this, "FIN QUI ",Toast.LENGTH_SHORT).show();
for (DataSnapshot messageSnapshot : dataSnapshot.getChildren()) {
// Toast.makeText(PlayTest.this, "QUI ",Toast.LENGTH_SHORT).show();
long numero_domande = (long) messageSnapshot.getValue();
ndomande[0] = (int) numero_domande;
Toast.makeText(PlayTest.this, "quante domande ci sono totali: "+ numero_domande,Toast.LENGTH_SHORT).show();
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
Toast.makeText(PlayTest.this, "???", Toast.LENGTH_SHORT).show();
}
});
//PROBLEM ON NDOMANDE
Toast.makeText(PlayTest.this, "x: "+ ndomande[0] ,Toast.LENGTH_SHORT).show();
Random random = new Random();
final int x = random.nextInt(ndomande[0]);
Toast.makeText(PlayTest.this, "x: "+ndomande[0] ,Toast.LENGTH_SHORT).show();
數組不返回查詢的值,但我爲初始化設置的值將幫助我做一個異步阻塞查詢某人可以幫助我?Firebase查詢幫助我