gpt4 book ai didi

java - 如何从中获取随机测验问题并在测验问题结束时添加听众

转载 作者:行者123 更新时间:2023-11-29 23:28:57 25 4
gpt4 key购买 nike

<分区>

我是一名教师,为我的学生休息创建了一个测验,我的 firebase 实时数据库中有 500 个问题 我想做的就是 随机化问题,每次50个问题设置一个监听器在50个问题之后显示结果

这是我的测验 Activity

public class grandtest extends AppCompatActivity {

TextView mQuestionTextView;
ProgressBar mProgressBar;
Button bchoice1,bchoice2,bchoice3,bchoice4;
Random Rand;
String mAnswer;
Timer mTimer;
TextView mScoreTextView;
public static int mScore;
int mQuestionNo = 0;

private Firebase mQuestionRef;
private Firebase mChoice1Ref;
private Firebase mChoice2Ref;
private Firebase mChoice3Ref;
private Firebase mChoice4Ref;
private Firebase mAnswerRef;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_grandtest);

mQuestionTextView = findViewById(R.id.mquestiontextview);
mProgressBar = findViewById(R.id.progressBar);
bchoice1 = findViewById(R.id.choice1);
bchoice2 = findViewById(R.id.choice2);
bchoice3 = findViewById(R.id.choice3);
bchoice4 = findViewById(R.id.choice4);
mScoreTextView = findViewById(R.id.mScore);
}


public void updateQuestion (){

mQuestionRef = new Firebase("https://class9notes-2808b.firebaseio.com/"+mQuestionNo +"/question");
mQuestionRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String question = dataSnapshot.getValue(String.class);
mQuestionTextView.setText(question);
}

@Override
public void onCancelled(FirebaseError firebaseError) {
Toast.makeText(grandtest.this,"Please enable data",Toast.LENGTH_SHORT).show();
}
});
mChoice1Ref = new Firebase("https://class9notes-2808b.firebaseio.com/"+mQuestionNo+"/choice1");
mChoice1Ref.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String choice1 = dataSnapshot.getValue(String.class);
bchoice1.setText(choice1);
}

@Override
public void onCancelled(FirebaseError firebaseError) {

}
});
mChoice2Ref = new Firebase("https://class9notes-2808b.firebaseio.com/"+mQuestionNo+"/choice2");
mChoice2Ref.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String choice2 = dataSnapshot.getValue(String.class);
bchoice2.setText(choice2);
}

@Override
public void onCancelled(FirebaseError firebaseError) {

}
});
mChoice3Ref = new Firebase("https://class9notes-2808b.firebaseio.com/"+mQuestionNo+"/choice3");
mChoice3Ref.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String choice3 = dataSnapshot.getValue(String.class);
bchoice3.setText(choice3);
}

@Override
public void onCancelled(FirebaseError firebaseError) {

}
});
mChoice4Ref = new Firebase("https://class9notes-2808b.firebaseio.com/"+mQuestionNo+"/choice4");
mChoice4Ref.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String choice4 = dataSnapshot.getValue(String.class);
bchoice4.setText(choice4);
}

@Override
public void onCancelled(FirebaseError firebaseError) {

}
});
mAnswerRef = new Firebase("https://class9notes-2808b.firebaseio.com/"+mQuestionNo+"/answer");
mAnswerRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
mAnswer = (String) dataSnapshot.getValue(String.class);
}

@Override
public void onCancelled(FirebaseError firebaseError) {

}
});
mQuestionNo ++;

我想随机化 mQuestionNo 对象以每次检索随机问题。这是我的 firebase 数据的结构

Firebase Data

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com