1
我在具有自定義光標適配器的LoaderManager中使用CursorLoader。我已經實現了顯示專輯和相關的藝術家,現在我想顯示封面。從MediaStore.Audio.Albums.ALBUM_ART顯示專輯藝術
這裏是我的自定義的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 disolay封面?謝謝。
我認爲使用BitMap可能會提高性能。 – h4ck3d
你有沒有設法提高速度? – h4ck3d
我怎樣才能生成位圖呢? –