0

thanks for reading. I'm making an app that can write musical scales based on input from spinners in the layout. I have 11 of Imageviews that take a LOT of information from a LOT of spinners, then those imageviews change on the click of a button in the layout. In short, I want to store the ImageViews in an ArrayList. This is my idea:

//Initilization of ArrayList as a member:
ArrayList<ImageView> pics;

//in onCreate():
pics = new ArrayList<ImageView>();
pics.add((ImageView) findViewById(R.id.picA);
pics.add((ImageView) findViewById(R.id.picB); //etc through picK

//in onClick():
for (int i; i++; i<11){
    if ("test".equals(noteArray[i]) pics[i].setImageResource(R.drawable.testPic);
    if ("testTwo".equals(noteArray[i]) pics[i].setImageResource(R.drawable.secondTestPic);

etc

But I am unable to use setImageResource() on pics[x]. It works fine on a regular ImageView object, am I using the ArrayList wrong?

1 Answer 1

1

use pics.get(i)

ArrayList uses uses a function to get an object at a particular location.

Sign up to request clarification or add additional context in comments.

2 Comments

So simple. Perhaps I shouldn't post on stackoverflow when I've a fever. I feel like I've wasted a question here. Either way, you were first and it worked fine, so I'll mark yours as best answer as soon as it lets me. Thank you!
Thanks! You could have easily answered you own question with a little research but we all lose patients sometimes (especially when sick). If your are interested, when you feel better do a little research on the Collections interface

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.