2016-11-10 118 views
1
  • 代码加载专辑封面负载专辑封面到滑翔使用列表视图

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

我想要的专辑封面装入使用滑翔列表视图。但是,我在遇到麻烦;

medialist.add(新SongInfo(..);

回答

0

你做错了: 使用这样的:

medialist.add(new SongInfo(thisID, thisTitle, thisArtist, thisAlbum,albumID)); 

现在,在您的列表视图适配器类,得到medialist中和在滑行方法中: 定义:

Context con; 

现在在适配器的构造:

public CustomAdapter(List<Medialist> items, Context context) { 
     medialist= items; 
     this.con = context; 
    } 

Glide.with(con) 
        .load(medialist.getAlbumID) 
        .asBitmap() 
        .into(imageview) 
+0

喜@Divyesh 我无法在我的适配器类初始化Glide.with(本),它说unresolve方法,我该怎么放在Glide.with后(.. )。 –