我想从可绘制的数组列表中设置图像,这是我的代码

 private ArrayList<Integer>  timeNames = new ArrayList<Integer>();
 timeNames.add(R.drawable.azaan_fajar_eng);
 timeNames.add(R.drawable.azaan_fajar_eng1);
 timeNames.add(R.drawable.azaan_fajar_eng2);
 timeNames.add(R.drawable.azaan_fajar_eng3);
 timeNames.add(R.drawable.azaan_fajar_eng4);
 timeNames.add(R.drawable.azaan_fajar_eng5);
 timeNames.add(R.drawable.azaan_fajar_eng6);


此代码不显示任何错误,但显示整数值而不是图像,请帮助我如何解决它?

最佳答案

您可以使用DrawabletimeNames加载图像,例如:

private ArrayList<Integer> timeNames = new ArrayList<Integer>();
timeNames.add(R.drawable.azaan_fajar_eng);
timeNames.add(R.drawable.azaan_fajar_eng1);
timeNames.add(R.drawable.azaan_fajar_eng2);
timeNames.add(R.drawable.azaan_fajar_eng3);
timeNames.add(R.drawable.azaan_fajar_eng4);
timeNames.add(R.drawable.azaan_fajar_eng5);
timeNames.add(R.drawable.azaan_fajar_eng6);

int[] type_img=new int[]{R.id.img1,R.id.img2,R.id.img3,R.id.img4,R.id.img5,R.id.img6,R.id.img7};

for(int i=0;i<timeNames.size();i++){

((ImageView)findViewById(type_img[i])).setImageResource(timeNames.get(i));
}

07-27 14:04