Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

use pics.get(i)

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

share|improve this answer
 
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! –  user2816570 Nov 25 '13 at 20:55
 
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 –  Scott Nov 25 '13 at 20:58
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.