我有一个问题,我有一个 GridView,我在其中使用 ImageView 加载图像,这些图像存储在 SD 中,为此我使用 Runnable 类进行加载。当它滚动 GridView 时,图像被加载到对应的框(ImageView)中,在其他表格中,我正在制作类似于音乐专辑列表的东西,图像被加载到专辑中,但也加载到另一个等等,你怎么能做同步?即如果一个充电,不被加载到另一个
我希望我明白
谢谢
PD:对不起我的英语
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater) getContext().getSystemService("layout_inflater");
v = vi.inflate(R.layout.listitemalbum, null);
}
bnSong = songs.get(position);
if (bnSong != null) {
coverAlbum = (ImageView) v.findViewById(R.id.imgCover);
coverAlbum.setScaleType(ImageView.ScaleType.CENTER_CROP);
if (bnSong.getAlbum() == null){
coverAlbum.setBackgroundResource(R.drawable.mksong);
}else{
try {
Runnable r = new Runnable() {
@Override
public void run() {
try{
Thread.sleep(1000);
Storage storage = new Storage();
cover = storage.getOpenImagen(bnSong.getAlbum(), "ALBUM");
}catch (Exception e){
e.printStackTrace();
}
coverAlbum.post(new Runnable() {
@Override
public void run() {
coverAlbum.invalidate();
coverAlbum.setImageBitmap(null);
if (cover != null){
coverAlbum.setImageBitmap(cover);
}else {
coverAlbum.setBackgroundResource(R.drawable.mksong);
}
}
});
}
};
new Thread(r).start();
} catch (Exception e) {
coverAlbum.setBackgroundResource(R.drawable.mksong);
}
}
}
return v;
}