2014-01-19 77 views
0

首先,我應該說我是Android編程新手...... 我正在檢索手機中的所有歌曲,並使用LoadManager和BindView在ListView中顯示以顯示數據。但是我無法在我的ImageView中顯示ALBUM_ART。從歌曲獲取ALBUM_ART

這正是我需要的...

Android ListView: how to avoid database query in bindView()? Need to fetch one to many relationship data

,但我不知道如何實現它。

我從我想loadermanager

@Override 
public void bindView(View view, Context contex, Cursor cursor) { 

TextView songText = (TextView) view.getTag(R.id.txt_title); 
TextView artistText = (TextView) view.getTag(R.id.txt_artist); 
ImageView albumImg = (ImageView) view.getTag(R.id.img_album); 

albumId = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ALBUM_ID)); 

和我之外的其他LoaderManager我bindView內部調用來檢索album_art

public class AlbumListItem implements LoaderManager.LoaderCallbacks<Cursor> { 

    @Override 
    public Loader<Cursor> onCreateLoader(int id, Bundle args) { 

     String[] projection = { 
       MediaStore.Audio.Albums._ID, 
       MediaStore.Audio.Albums.ALBUM_ART, 
    }; 


     return new CursorLoader(MainActivity.this, MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, projection 
       , MediaStore.Audio.Albums.ALBUM_ID + " = ?", new String[]{albumId}, null); 
    } 

    @Override 
    public void onLoadFinished(Loader<Cursor> arg0, Cursor arg1) { 
     // TODO Auto-generated method stub 

    } 

    @Override 
    public void onLoaderReset(Loader<Cursor> arg0) { 
     // TODO Auto-generated method stub 

    } 

} 

但正如我說我不歌曲BindView知道如何(或在哪裏)插入或初始化AlbumListItem loader getLoaderManager()。initLoader(ID,null,MainActivity.this);

謝謝!

回答

0

我有一個類似的程序,源代碼是https://github.com/pbirdsall/jasonisframed。隨意看看,看看是否有幫助。我基本上拉文本和圖像,將它們加載到數據庫並將它們放入列表視圖。