user3247199 user3247199 - 3 months ago 17
Java Question

Remove random item from 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?

here is how I did it:

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

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


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

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.

Answer

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

myArrayList.remove(rando);
Comments