0

リストビューに画像を入力しようとしていますが、その URI はカーソルから返されます。

シンプルカーソアダプターでビューバインダーを使用する必要があるのか​​ 、それとも同じ仕事をするカスタムのシンプルカーソアダプターを作成する必要があるのか​​ わかりません。また、これらのオプションのいずれかを実装する方法もわかりません。

私のアダプターには次のものがあります。

SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
        R.layout.albumitem, albumCursor, displayFields, displayViews);


String[] displayFields = new String[] { AudioColumns.ALBUM,
        AudioColumns.ARTIST, AlbumColumns.NUMBER_OF_SONGS };

int[] displayViews = new int[] { R.id.albumTitle, R.id.artistTitle,
        R.id.totalSongs};

しかし、R.id.albumView にも画像を追加したいと思います。

カーソルから AlbumColumns.ALBUM_ID を取得し、次のコードを使用して、通常 (アダプターの外部) で画像を取得できます。

currentAlbumId = idList.get(currentSongIndex);
currentAlbumIdLong = Integer.parseInt(currentAlbumId);
artworkUri = Uri.parse("content://media/external/audio/albumart");
currentSongUri = ContentUris.withAppendedId(artworkUri, currentAlbumIdLong);
albumArt.setImageURI(currentSongUri);

私の問題は、アダプター内で同様のタスクを実行する方法がわからないことです。とにかく、私の最善の推測は、viewBinder を使用することです。誰かが親切にこれを実装する方法を教えてもらえますか?

ご協力ありがとうございました。

- 編集 -

2つの素晴らしい答え。あなたがた両方に感謝します。

4

2 に答える 2

0
private class YourCustomAdatper extends CursorAdapter{

private final LayoutInflater mInflater;

public YourCustomAdatper(Context context, Cursor cursor) {
super(context, cursor, true);
mInflater = LayoutInflater.from(context);
  }

@Override
public void bindView(View view, Context context, final Cursor cursor)
{
ImageView imageview=view.findViewById(yourImageview_id);
//do rest of task
    }

@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
final View view =mInflater.inflate(yourLayout, parent, false);

return view;
    }

}
于 2012-06-04T06:31:16.330 に答える
0

カスタム CursorAdpater を使用できます。必要な引数を Custom クラスのコンストラクターに渡します。newView でレイアウトを膨張させ、bindView で値を設定します。http://blog.cluepusher.dk/2009/11/16/creating-a-custom-cursoradapter-for-android/を参照してください。

于 2012-06-04T06:25:38.187 に答える