I don’t know if this is the best solution, but you can create a “manager” for your checkboxes and run it when any of them is clicked.
For simplicity, I added a manager to the xml code, but feel free to use setOnClickListener or setOnCheckedChangeListener.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CheckBox1"
android:onClick="cbgroupmanager"
/>
...
<CheckBox
android:id="@+id/checkBox5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CheckBox5"
android:onClick="cbgroupmanager"/>
</LinearLayout>
You need an ArrayList to iterate, so you can set the status of each flag when they are clicked.
public class Q6910875 extends Activity
ArrayList<CheckBox> cb = new ArrayList<CheckBox>();
int CheckBoxNum = 5;
Iterator<CheckBox> itr ;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
cb.add((CheckBox) findViewById(R.id.checkBox1));
cb.add((CheckBox) findViewById(R.id.checkBox2));
cb.add((CheckBox) findViewById(R.id.checkBox3));
cb.add((CheckBox) findViewById(R.id.checkBox4));
cb.add((CheckBox) findViewById(R.id.checkBox5));
itr = cb.iterator();
}
, , , , , !
public void cbgroupmanager(View v) {
CheckBox cbaux;
while(itr.hasNext()) {
cbaux = (CheckBox) itr.next();
Log.d("soa", "click");
if (cbaux.equals(v))
cbaux.setChecked(true);
else
cbaux.setChecked(false);
}
, , , , .