Android random activites without repetition

后端 未结 2 1780
谎友^
谎友^ 2021-01-28 04:08

I am developing a quiz game, where I have to get random activities on answering the questions as to avoid the questions in same order. I have fixed this by using switch

2条回答
  •  不知归路
    2021-01-28 05:14

    Follow these steps:

    1. Create an ArrayList (or a List simply) and add all your Questions to it. Remember this only holds the questions for shuffling. Do not use it for any other purpose.
    2. Then do a shuffle using Collections.shuffle(question).
    3. Ask the question on top (question.get(0));
    4. After this has been answered remove it from the List. This will ensure it is never shown again.
    5. Repeat steps 2 - 5 till your List size is greater than zero.

    Let me know if it is unclear.

提交回复
热议问题