简体   繁体   English

Android,ArrayList中的ImageView对象

[英]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. 我有11个Imageview,它们从很多微调器中获取很多信息,然后单击布局中的一个按钮,这些imageview就会改变。 In short, I want to store the ImageViews in an ArrayList. 简而言之,我想将ImageViews存储在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]. 但是我无法在pics [x]上使用setImageResource()。 It works fine on a regular ImageView object, am I using the ArrayList wrong? 它可以在常规ImageView对象上正常工作,我使用ArrayList错误吗?

use pics.get(i) 使用pics.get(i)

ArrayList uses uses a function to get an object at a particular location. ArrayList使用使用函数来获取特定位置的对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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