私はlist.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);でsimple_list_item_multiple_choiceを使用しています。データベースクエリから入力されたチェックボックスのリストを作成します。次に、onListItemClickを使用してリストのクリックを処理していますが、これも正常に機能しています。(5日後)どうしようもないのは、リスト項目に付いているチェックボックスがチェックされているかどうかに基づいてifステートメントを書くことです。必要なのは、以下の例と同等です。これは、android:onClick要素を使用して以下のメソッドを起動できるチェックボックスで完全に機能します。
public void onCheckboxClicked(View v) {
// Perform action on clicks, depending on whether it's now checked
if (((CheckBox) v).isChecked()) {
Toast.makeText(this, "Selected", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "Not selected", Toast.LENGTH_SHORT).show();
}
}
これは私のアプリにとって重要なので、アドバイスをいただければ幸いです。以下は、simpleCusrorAdapterが使用しているものです。
Cursor cursor3 = db.rawQuery("SELECT _id, symname FROM tblsymptoms WHERE _id IN ("+sympresult+") ", null);
adapter = new SimpleCursorAdapter(
this,
android.R.layout.simple_list_item_multiple_choice,
cursor3,
new String[] {"symname","_id"},
new int[] {android.R.id.text1});
setListAdapter(adapter);
ListView list=getListView();
list.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);