简体   繁体   中英

Android, ImageView objects in ArrayList

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?

use pics.get(i)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM