I am developing an application which involves a quiz in it. I have used a viewflipper for displaying question, as i press the next button it flips to next question. However, I wish to display these questions randomly. I have parsed an xml and displayed the questions n its options !
Asked
Active
Viewed 1,055 times
-1
-
and do you have a more detailed question as well as code for us? – nano_nano Feb 14 '13 at 09:26
-
How are you displaying the questions and answers? Are you storing them somehwhere ? – Anukool Feb 14 '13 at 09:27
-
I am getting them from the xml....have a pojo class which has a setter n getter... – HelpNeeded Feb 14 '13 at 09:29
1 Answers
1
Assuming that all your questions stored in array
or some data structure e.g. ArrayList
You need to define a single random object only once in your activity
e.g.
Random random = new Random();
Get the next question index:
int nextQuestionIndex = random.nextInt(n); // where n is the total number of questions

iTech
- 18,192
- 4
- 57
- 80