SimpleCursorAdapter を拡張してカスタム ListView を作成しました。結果は IMAGE + CheckedTextView (テキスト + チェックボックス) です。
アイテムを長押しすると、すべて正常に動作します。クリックしたアイテムの正しい ID と詳細を取得します。
アイテムをチェック済みとしてマークしようとすると問題が発生しますが、間違ったチェックボックスがチェックされます。
例:リストに 9 つの項目があり、1 から 9 の順に並べ替えられています。listItem 1 をクリックすると、9 行目のチェックボックスがチェックされます。項目 4 をクリックすると、6 行目のチェックボックスがチェックされ、中央の行をクリックするとチェックされます。
明らかに、ここに何かが欠けています:)行を長押しすると(contextMenuが開きます)、すべてがうまく機能します。
これはリスナーです:
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
CheckedTextView markedItem = (CheckedTextView) view.findViewById(R.id.btitle);
if (!markedItem.isChecked()) {
markedItem.setChecked(true);
} else {
markedItem.setChecked(false);
}
}
});
どんな助けにも感謝します!
さらにコードを投稿する必要がある場合はお知らせください。
ありがとうございました!
ところで、複数をクリックすると... PARTYが続きます...明らかな順序はありません...
編集: アダプタ コード
public class ImageCursorAdapter extends SimpleCursorAdapter {
private Cursor c;
private Context context;
private String url;
private TextView bUrl;
public ImageCursorAdapter(Context context, int layout, Cursor c,
String[] from, int[] to) {
super(context, layout, c, from, to);
this.c = c;
this.context = context;
}
public View getView(int pos, View inView, ViewGroup parent) {
View v = inView;
if (v == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(R.layout.image_list, null);
}
this.c.moveToPosition(pos);
final TextView bTitle = (TextView) v.findViewById(R.id.btitle);
String bookmark = this.c.getString(this.c.getColumnIndex(Browser.BookmarkColumns.TITLE));
byte[] favicon = this.c.getBlob(this.c.getColumnIndex(Browser.BookmarkColumns.FAVICON));
if (favicon != null) {
ImageView iv = (ImageView) v.findViewById(R.id.bimage);
iv.setImageBitmap(BitmapFactory.decodeByteArray(favicon, 0, favicon.length));
}
bTitle.setText(bookmark);
return (v);
}
}