设置ImageView的新ImageView的
问题描述:
我想显示由点击从我的文件夹绘制的三幅图像的列表。但是,images.get(i)部分给我一个错误。我不明白。如果我更换与R.drawable.handbag它的工作原理,但我的ArrayList它不工作(即使它有同样的事情)设置ImageView的新ImageView的
public void addListenerOnButton() {
images.add(R.drawable.handbag); // these images have been added
images.add(R.drawable.shoes);
images.add(R.drawable.tie);
image = (ImageView) findViewById(R.id.imageView1);
nextOne = (Button) findViewById(R.id.btnChangeImage);
nextOne.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
i++;
if (i > 2){
i = 0;
}
image.setImageResource((images.get(i)));
}
});
答
创建图像阵列如下面
private static int images[]={R.drawable.handbag,R.drawable.shoes,R.drawabletie.tie};
然后如下
image.setImageResource((images[i]));
使用或整型创建的ArrayList如下
List<Integer> images = new ArrayList<Integer>();
答
刚刚尝试像这样
int images[]={R.drawable.handbag,R.drawable.shoes,R.drawabletie.tie};
同方式
List<Integer> images = new ArrayList<Integer>();
images.add(R.drawable.handbag); // these images have been added
images.add(R.drawable.shoes);
images.add(R.drawable.tie);
答
改变你的ArrayList的类型,就像这样:
ArrayList<Integer> images = new ArrayList<>();
什么是你所得到的错误?发布你的logcat。 –
也请你展示如何创建我和图像 –
请检查您的图片在ImageView的 –