从 ArrayList 中删除随机项 [英] Remove random item from ArrayList

查看:30
本文介绍了从 ArrayList 中删除随机项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是安卓新手.我有一个字符串 ArrayList,该 ArrayList 包含随机选择并在 TextView 中设置的问题.当用户单击下一步时,它应该转到下一个活动以获取另一个问题,该问题也是从 ArrayList 中选择的.我想从 Arraylist 中删除第一个问题以防止在第二个活动中重复.我怎样才能做到这一点?

I'm new to android. I have an ArrayList of strings and that ArrayList contain questions that are selected randomly and set in a TextView. when the user click next it Should be go to the next activity for another question which is also selected from the ArrayList. I want to remove the first question from the Arraylist to prevent duplication in the second activity. How can I do that?

我是这样做的:

int rando = (int)((Math.random()*10));

textView.setText(myArrayList.get(rando));

我正在使用 Intent 将 myArrayList 传递给第二个活动.

I'm using Intent to pass myArrayList to the second activity.

但我不知道如何在进行下一个活动之前删除 textView 中的项目.我使用了 myArrayList.remove(textView.getText());但不工作.

but I can't figure out how to remove the item in the textView before going the next activity. I used myArrayList.remove(textView.getText()); but not working.

推荐答案

首先,保留rando值.然后在您开始下一个活动时使用它,如下所示:

First, keep the rando value. then use it when you're starting the next activity like this:

myArrayList.remove(rando);

这篇关于从 ArrayList 中删除随机项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆