我在带有自定义 CursorAdapter 的 LoaderManager 中使用 CursorLoader。我已经实现了显示专辑和相关的艺术家,现在我想显示封面。
这是我的自定义 CursorAdapter :
public class AlbumsAdapter extends CursorAdapter {
private final LayoutInflater mInflater;
public AlbumsAdapter(Context context, Cursor c) {
super(context, c);
mInflater=LayoutInflater.from(context);
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
TextView albumTitle =(TextView)view.findViewById(R.id.albumTextView);
albumTitle.setText(cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Albums.ALBUM)));
TextView artistName=(TextView)view.findViewById(R.id.artistTextView);
artistName.setText(cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Albums.ARTIST)));
ImageView albumCover=(ImageView)view.findViewById(R.id.artistTextView);
// Here what should I do ?
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
final View view=mInflater.inflate(R.layout.albums_row,parent,false);
return view;
}
}
我尝试了以下但没有成功:
String path = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Albums.ALBUM_ART));
File imgFile = new File(path);
if(imgFile.exists()){
Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
ImageView albumCover=(ImageView)view.findViewById(R.id.album_cover);
albumCover.setImageBitmap(myBitmap);
}
MediaStore.Audio.Albums.ALBUM_ART 返回什么以及如何使用它来使 ImageView 脱离封面?谢谢。