Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在开发一个涉及测验的应用程序。我使用 viewflipper 来显示问题,当我按下下一个按钮时,它会翻转到下一个问题。但是,我希望随机显示这些问题。我已经解析了一个 xml 并显示了问题 n 它的选项!
假设您的所有问题都存储在array或某些数据结构中,例如ArrayList
array
ArrayList
您只需在活动中定义一个随机对象一次
例如
Random random = new Random();
获取下一个问题索引:
int nextQuestionIndex = random.nextInt(n); // where n is the total number of questions