我在Firebase中有一个在线测验应用程序。随机播放方法不起作用。每次问题的间隔都相同。
每次问题都相同。带有相同的顺序。我不明白为什么会这样。
这个问题实际上很简单,但是我必须扩大接受范围。
private void loadQuestions(String categoryId) {
//First, clear list if have old questions
if (Common.questionList.size()>0)
Common.questionList.clear();
question.orderByChild("categoryId").equalTo(categoryId).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot postSnapshot : dataSnapshot.getChildren()) {
Question question = postSnapshot.getValue(Question.class);
Common.questionList.add(question);
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {}
});
//Random list
Collections.shuffle(Common.questionList);
}
public class Question {
private String sul, bri, ki, cu, dor, du, categoryId, sek;
public Question() {
}
public Question(String sul, String bri, String ki, String cu, String dor, String du, String categoryId, String sek) {
this.sul = sul;
this.bri = bri;
this.ki = ki;
this.cu = cu;
this.dor = dor;
this.du = du;
this.categoryId = categoryId;
this.sek = sek;
}
public String getSul() {
return sul;
}
public void setSul(String sul) {
this.sul = sul;
}
public String getBri() {
return bri;
}
public void setBri(String bri) {
this.bri = bri;
}
public String getKi() {
return ki;
}
public void setKi(String ki) {
this.ki = ki;
}
public String getCu() {
return cu;
}
public void setCu(String cu) {
this.cu = cu;
}
public String getDor() {
return dor;
}
public void setDor(String dor) {
this.dor = dor;
}
public String getDu() {
return du;
}
public void setDu(String du) {
this.du = du;
}
public String getCategoryId() {
return categoryId;
}
public void setCategoryId(String categoryId) {
this.categoryId = categoryId;
}
public String getSek() {
return sek;
}
public void setSek(String sek) {
this.sek = sek;
}
}
public class Common {
public static String categoryId,categoryName;
public static User currentUser;
public static List<Question> questionList = new ArrayList<>();
public static final String STR_PUSH = "pushNotification";
}
答案 0 :(得分:0)