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.
Try using
myList.remove(rando);
, whererando
is indexoutput
First, keep the rando value. then use it when you're starting the next activity like this:
You can try to remove item by it's position.
instead of this,
you have to use below code