说我有一个循环,该循环创建ImageViews并将其添加到布局中

final LinearLayout linLayRow1 = (LinearLayout) findViewById(R.id.LLrow1);
    ...
try {
FileInputStream in1 = new FileInputStream(masterPath+shiftimage);
BufferedInputStream buf1 = new BufferedInputStream(in1);
Bitmap bMap1 = BitmapFactory.decodeStream(buf1);
ivBtnSym.setImageBitmap(bMap1);
in1.close();
buf1.close();
} catch (Exception e) { }
    ...
linLayBtnInside.addView(ivBtnSym);


现在,我需要将ImageView的位图更改为例如masterPath +“ / 1.png”更改为masterPath +“ / 2.png” ...您将如何操作?

谢谢! :)

最佳答案

如果您确定图像名称是唯一的

您可以尝试使用标签:

final LinearLayout linLayRow1 = (LinearLayout) findViewById(R.id.LLrow1);
    ...
try {
FileInputStream in1 = new FileInputStream(masterPath+shiftimage);
BufferedInputStream buf1 = new BufferedInputStream(in1);
Bitmap bMap1 = BitmapFactory.decodeStream(buf1);
ivBtnSym.setImageBitmap(bMap1);
ivBtnSym.setTag(masterPath+shiftimage);
in1.close();
buf1.close();
} catch (Exception e) { }
    ...
linLayBtnInside.addView(ivBtnSym);


现在,当您要检索ImageView时:

ImageView retrieved = (ImageView) linLayBtnInside.findViewByTag(query);

09-05 12:36