-1
我想使隨機測驗應用程序使用數組,所以我想保持重複。你能提出一些我可以實現的方法嗎?我已經添加了下面的代碼來獲得我所擁有的代碼。我不知道我需要做什麼。使用陣列隨機測驗應用程序使用數組
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.quiz);
QuestionMaker();
}
此功能將使一大堆的問題:
//funtion makes the load of the question
public void QuestionMaker(){
QText=(TextView) findViewById(R.id.textView_questions);
Qgroup=(RadioGroup)findViewById(R.id.Group_radio);
btnNext=(Button)findViewById(R.id.button_next);
final ArrayList<String> distractorList = new ArrayList<String>();
Collections.addAll(distractorList, Options);
//first time of filling the form
int length = question.length;
for (int i = 0; i < length; i++)
quiz.add(new QuestionAndAnswer(question[i], answer[i], distractorList.subList(i * 3, (i + 1) * 3)));
Collections.shuffle(quiz);
fillInQuestion();
//clicking the radio button this happen
Qgroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
makefinish++;
QuestionAndAnswer qna = quiz.get(currentQuestion);
qna.selectedAnswer = ((RadioButton) group.findViewById(checkedId)).getText().toString();
if (qna.selectedAnswer == qna.answer) {
correctcounter++;
//correct message
}
if (!(qna.selectedAnswer == qna.answer)) {
//wrong answer message
}
}
//function that makes the filling
public void fillInQuestion() {
QuestionAndAnswer qna = quiz.get(currentQuestion);`enter code here`
QText.setText(qna.question);
int count = Qgroup.getChildCount();
for (int i = 0; i < count; i++)
((RadioButton) Qgroup.getChildAt(i)).setText(qna.allAnswers.get(i));
}