Friends、Android ExpandableListView ChildViewのCheckBox
ChildViewで単一選択チェックボックスを使用するExpandableListViewを作成しようとしています。 そして、私はExpandableListViewのOnChildClickListener()で他のCheckBoxを "false"に設定する方法を理解できません。ここに私のコードは次のとおりです。ここ
ExpListView.setOnChildClickListener(new OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
CheckBox cb = (CheckBox) v.findViewById(R.id.checkbox);
if (cb.isChecked()) {
} else {
cb.setChecked(true);
//Here somehow I must set all other checkboxes to false.
//Is it possible?
}
return false;
}
});
はChildViewのxmlです:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/textChild"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:textColor="@android:color/white"
android:layout_weight="1"
/>
<CheckBox android:id="@+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:clickable="false"
android:layout_gravity="right"
android:visibility="visible"
/>
</LinearLayout>
ExpandableListViewのすべての子を再帰的に移動し、別のチェックボックスを見つけることができます。選択したセクションの親ビューを最初に見つけて(自分のIDがわからない場合)、そのチェックボックスを取得することをお勧めします。または、チェックボックスを配列で保持し、チェック状態を変更してnotifyDataSetChanged()メソッドを呼び出します。 –
2番目の提案を教えてもらえますか?これは私がしたいことですが、私はAndroidで新しく、選択したセクションで他のチェックボックスを探す方法を理解できません – Dlash
ExpListViewの初期化と読み込みに関連するコードをもっと提供できますか? –