0

This is a part of my code:

int n= random.nextInt(images.length - 1);        
iv.setImageResource(images[n]);  

Int n choose one of the indexes randomly and then I used ImageResource to show pictures according to the the random indexes. Now I want to add n to ArrayList. How should I do it? Is there any better way to save a value in memory in android?

1 Answer 1

2

Declare a ArrayList like the one below,

ArrayList<Integer> list = new ArrayList<Integer>();

And once you set the Image add that to your ArrayList like this,

int n = random.nextInt(images.length - 1);        
iv.setImageResource(images[n]);  
list.add(n);
Sign up to request clarification or add additional context in comments.

2 Comments

i for an arraylist is maybe not the best variable choice.
@assylias you are absolutely right.. well, you know competition in who first posts the valuable answer is much more important right. So to cut the time, I just used a one letter variable.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.