当我按下按钮时,我想从firebase android逐个检索数据,但问题是当点击按钮时,我得到第一个孩子,第二次点击时我没有得到第二个孩子。
public void nextQuestion(View view) {
mRef = FirebaseDatabase.getInstance().getReferenceFromUrl("https:..../Questions");
mRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot postSnapshot : dataSnapshot.getChildren()) {
GetData gd = postSnapshot.getValue(GetData.class);
String value = gd.getQuestion();
String rb1 = gd.getAnswerA();
String rb2 = gd.getAnswerB();
String rb3 = gd.getAnswerC();
String answer = gd.getCorrectAnswer();
pytja.setText(value);
aR.setText(rb1);
bR.setText(rb2);
cR.setText(rb3);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}