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封面?謝謝。

回答

8

我已經取得了加載專輯涵蓋了ImageViews有:

String coverPath = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Albums.ALBUM_ART)); 
    Drawable img = Drawable.createFromPath(coverPath); 
    ImageView coverAlbum=(ImageView)view.findViewById(R.id.album_cover); 
    coverAlbum.setImageDrawable(img); 

的問題是,該名單是很慢的。我想我應該縮小封面的分辨率來消耗更少的內存。

+0

我認爲使用BitMap可能會提高性能。 – h4ck3d

+0

你有沒有設法提高速度? – h4ck3d

+0

我怎樣才能生成位圖呢? –