0
FirebaseDatabaseに問題があります。私は、日付ベースのリファレンスから子の数を読みたいと思います。そして私はこれを5回したい。だから私は5つのSingleEventListenersを作成し、この日付のユーザーがいなければ値を設定します。 (私は私が何をしたいのか、あなたは理解してほしい:D)FirebaseDatabaseデータを待つのではなく、何ができますか?
while (counter<5) {
... We create a new date and username here. We have to do this 5 times
myRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (!(dataSnapshot.child(finalDate).hasChild(username)))
myRef.child(finalDate).child(username).setValue(true);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
counter++;
}
try { //TODO Synchronisation is not given without that block
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
...
...
...
myRef.child(chosenDate).child(username).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
participate.setChecked((Boolean) dataSnapshot.getValue());
}
我々は日付を受信するために待機していない場合はここでは、nullポインタ例外を取得します。 sleep()の代わりに何ができるのですか。本当に悪いです:(