我创建了一个包含延迟加载图像的列表视图。图像来自互联网。如何获取当前选定的图像位图并将该位图设置为其他图像视图?
我使用了这段代码但不起作用:
mUuserGallery.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
ListAdapter lList = mUuserGallery.getAdapter();
final View imageView1 = (View)lList.getView(position, view, parent);
final ImageView imageView3 = (ImageView) imageView1.findViewById(R.id.imageIcon);
imageView3.setDrawingCacheEnabled(true);
imageView3.buildDrawingCache();
if (imageView3.getDrawable() instanceof BitmapDrawable) {
b = ((BitmapDrawable) imageView3.getDrawable()).getBitmap();
} else {
Drawable d = imageView3.getDrawable();
b = Bitmap.createBitmap(300, 300, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(b);
d.draw(canvas);
}
mImgViewer = (ImageView)mView.findViewById(R.id.imageView2);
mImgViewer.bringToFront();
mImgViewer.setImageBitmap(b);
}
});
答案 0 :(得分:0)
延迟加载,因为您知道依赖于在某些数据结构上使用那些可绘制或位图以供您使用。 (列表视图滚动)。
如果您使用地图数据结构来存储drawable:
Map<String, Drawable> drawableMap;
所以,你可以得到以下内容:
if (drawableMap.containsKey(urlString)) {
return drawableMap.get(urlString);
}
使用位置从列表视图适配器获取urlString。
答案 1 :(得分:0)
试试这个:
mImgViewer.setImageDrawable(imageView3.getDrawable());