複数選択のためにチェックボックスを使用したいリストビューがあります
android:choiceMode="multipleChoice"
が、XML ファイルに追加すると、ボックスのチェックが適切ではありません。
ListView の行を表示するにはダブルタップし、もう一度消すにはシングルタップする必要があります。
なくても動作android:choiceMode="multipleChoice"
しますが、ListView を使用できなくなります。
getCheckedItemPositions()
なぜこれが起こっているのか誰にも考えがありますか?
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/nameList"
android:choiceMode="multipleChoice"
tools:listitem="@android:layout/simple_list_item_checked"
android:layout_centerHorizontal="true" android:layout_alignParentTop="true"
android:layout_above="@+id/button"/>
Activity クラスのコードを次に示します。
listAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_checked, stringArray);
playerList = (ListView)this.findViewById(R.id.nameList);
playerList.setAdapter(listAdapter);
//onClickListener
playerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
CheckedTextView checkedTextView = (CheckedTextView) view;
checkedTextView.toggle();
}
});
私を助けてください..事前に感謝