[英]Retrieve mcq data from firebase realtime database with options
我想從我的 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);
}
我希望它以隨機方式而不是順序方式獲取,例如:1,2
您可以檢索所有 mcq 並將它們保存在 arraylist 中,稍后使用
Collections.shuffle(arrayList);
你可以洗牌。 要了解有關隨機播放和用法的更多信息,您可以點擊此鏈接
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.