我想从我的Android应用中的Firebase实时数据库中检索我的mcq。
下面是相同的代码。
databaseReference = FirebaseDatabase.getInstance().getReference().child("Questions").child(String.valueOf(computerCount));
databaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
final Question question = dataSnapshot.getValue(Question.class);
questionTxt.setText(question.getQuestion());
b1.setText(question.getOption1());
b2.setText(question.getOption2());
b3.setText(question.getOption3());
b4.setText(question.getOption4());
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(b1.getText().toString().equals(question.answer))
{
Toast.makeText(getApplicationContext(),"Correct answer",Toast.LENGTH_SHORT).show();
b1.setBackgroundColor(Color.GREEN);
correct = correct +1;
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
b1.setBackgroundColor(Color.parseColor("#03A9F4"));
updateQuestion();
}
}, 1500);
}
我希望以随机方式而不是顺序方式来获取ex:1,2
您可以检索所有的mcq,并将它们保存在arraylist中,然后使用
Collections.shuffle(arrayList);
您可以将它们洗牌。要了解有关随机播放和用法的更多信息,请点击此链接
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句