0

カスタムアダプタと複数選択を使用してlistViewを作成しようとしています。私のアダプターは次のようになります。

public class MusicPopupListAdapter extends BaseAdapter {

Cursor cursor;
Context context;
public MusicPopupListAdapter(Context context) {
    this.context = context;
    Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
    String[] cursor_cols = {
            MediaStore.Audio.Media._ID,
            MediaStore.Audio.Media.ARTIST,
            MediaStore.Audio.Media.ALBUM,
            MediaStore.Audio.Media.TITLE,
    };
    String where = MediaStore.Audio.Media.IS_MUSIC + "=1";
    cursor = context.getContentResolver().query(uri, cursor_cols, where, null, null);
}


@Override
public int getCount() {
    return cursor.getCount();
}

@Override
public Track getItem(int position) {
    cursor.moveToPosition(position);
    Track track = new Track();
    track.id = cursor.getLong(cursor.getColumnIndex(MediaStore.Audio.Media._ID));
    track.album = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ALBUM));
    track.artist = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ARTIST));
    track.title = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.TITLE));
    return track;
}

@Override
public long getItemId(int position) {
    Track track = getItem(position);
    return track.id;
}


@Override
public View getView(int position, View convertView, ViewGroup parent) {
    RowHandler handler;
    if (convertView == null) 
    {
        convertView = LayoutInflater.from(context).inflate(R.layout.row, parent, false);
        handler = new RowHandler();
        handler.artist = (TextView) convertView.findViewById(R.id.artist);
        handler.album = (TextView) convertView.findViewById(R.id.album);
        handler.title = (TextView) convertView.findViewById(R.id.title);
        convertView.setTag(handler);
    }
    else
        handler = (RowHandler)convertView.getTag();
    Track track = getItem(position);
    handler.artist.setText(track.artist);
    handler.album.setText(track.album);
    handler.title.setText(track.title);
    return convertView;
}

public static class Track {
    long id;
    String artist;
    String album;
    String title;
}

public static class RowHandler {
    TextView artist;
    TextView album;
    TextView title;
}

行のレイアウトとして、拡張相対レイアウトを使用しています。

public class CheckableRelativeLayout extends RelativeLayout implements Checkable {

boolean checked = false;
public CheckableRelativeLayout(Context context) {
    super(context);
}

public CheckableRelativeLayout(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public CheckableRelativeLayout(Context context, AttributeSet attrs, int style)
{
    super(context, attrs, style);
}

@Override
public boolean isChecked() {
    return checked;
}

@Override
public void setChecked(boolean checked) {
    this.checked = checked;
}

@Override
public void toggle() {
    checked=!checked;
}

デバッグでは、そのsetCheckedが呼び出していますが、常にfalse値を使用しています。

そして、listViewの選択モードをListView.CHOICE_MODE_MULTIPLEに設定しました。私は何が欠けていますか?

4

1 に答える 1

0

解決策を見つけました。問題はポップアップウィンドウにありました。デフォルトでは、ポップアップ ウィンドウはフォーカス不可モードで作成されました。解決策は、ポップアップ ウィンドウ focusable = true を設定することです。

于 2012-12-24T07:21:58.010 に答える