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

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

问题描述

我是Android新手.我有一个字符串的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天全站免登陆