android,如何通过其位图查找ImageView?

时间:2011-08-10 17:48:37

标签: java android

假设我有一个创建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”......你会怎么做?

谢谢! :)

1 个答案:

答案 0 :(得分:1)

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

你可以尝试使用标签:

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);