This question already has an answer here:
- How to shuffle an ArrayList [duplicate] 2 answers
I want to randomize the radio button. In my radio button 4 options are there choice1
choice2
choice3
and the answer
by default I have set the answer as fix now, I want to shuffle so it will check directly and can calculate score
Here is the code what I have done till now. Radio button values are getting randomize not radio button. All 4 radio button are in radio group Suggest some solution or any other idea
Code
choice1 =(exp.getString("choice1"));
choice2 =(exp.getString("choice2"));
choice3 =(exp.getString("choice3"));
answer =(exp.getString("answer"));
ropt0.setText("" + choice1);
ropt1.setText("" + choice2);
ropt2.setText("" + choice3);
ranswer.setText("" + answer);
ArrayList<String> arrayText = new ArrayList<>();
arrayText.add(choice1);
arrayText.add(choice2);
arrayText.add(choice3);
arrayText.add(answer);
Collections.shuffle(arrayText);
for (int j = 0; j < rdgrp.getChildCount(); j++) {
RadioButton rb = (RadioButton) rdgrp.getChildAt(j);
rb.setText(arrayText.get(j));
}
Aucun commentaire:
Enregistrer un commentaire