加载专辑封面的代码
if(cursor != null && cursor.moveToFirst()){
int titleColumn = cursor.getColumnIndex(MediaStore.Audio.Media.TITLE);
int idColumn = cursor.getColumnIndex(MediaStore.Audio.Media._ID);
int artistColumn = cursor.getColumnIndex(MediaStore.Audio.Media.ARTIST);
int albumColumn = cursor.getColumnIndex(MediaStore.Audio.Media.ALBUM);
long albumID = cursor.getColumnIndex(MediaStore.Audio.Albums.ALBUM_ID);
do {
long thisID = cursor.getLong(idColumn);
String thisTitle = cursor.getString(titleColumn);
String thisArtist = cursor.getString(artistColumn);
String thisAlbum = cursor.getString(albumColumn);
Glide.with(this)
.load(albumID)
.asBitmap()
.into() //How do I return a value?
medialist.add(new SongInfo(thisID, thisTitle, thisArtist, thisAlbum, //Bitmap variable));
}
while (cursor.moveToNext());
我正在尝试使用Glide将专辑封面加载到列表视图中。但是,我遇到了麻烦;
medialist.add(新的SongInfo(..);
答案 0 :(得分:0)
medialist.add(new SongInfo(thisID, thisTitle, thisArtist, thisAlbum,albumID));
现在,在listview适配器类中,获取medialist并使用glide方法: 定义:
Context con;
现在在适配器的构造函数中:
public CustomAdapter(List<Medialist> items, Context context) {
medialist= items;
this.con = context;
}
Glide.with(con)
.load(medialist.getAlbumID)
.asBitmap()
.into(imageview)