1

我在带有自定义 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 脱离封面?谢谢。

4

1 回答 1

7

我已经实现了在ImageViewswith 中加载专辑封面:

    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);

问题是列表非常慢。我想我应该缩小封面的分辨率以消耗更少的内存。

于 2012-06-15T09:53:11.743 回答