Search code examples
androidrandomviewflipper

Displaying random questions in an application


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 !


Solution

  • 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