<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginTop="26dp"
android:text="CheckBox" />
<CheckBox
android:id="@+id/checkBox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/checkBox1"
android:layout_below="@+id/checkBox1"
android:text="CheckBox" />
<CheckBox
android:id="@+id/checkBox3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/checkBox2"
android:layout_below="@+id/checkBox2"
android:text="CheckBox" />
<CheckBox
android:id="@+id/checkBox4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/checkBox3"
android:layout_below="@+id/checkBox3"
android:text="CheckBox" />
</RelativeLayout>
package com.example.jmj;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
public class MainActivity extends Activity {
<span style="white-space:pre"> </span>
<span style="white-space:pre"> </span>private CheckBox a,b,c,d =null;
<span style="white-space:pre"> </span>
<span style="white-space:pre"> </span>
<span style="white-space:pre"> </span>@Override
<span style="white-space:pre"> </span>protected void onCreate(Bundle savedInstanceState) {
<span style="white-space:pre"> </span>super.onCreate(savedInstanceState);
<span style="white-space:pre"> </span>setContentView(R.layout.activity_main);
<span style="white-space:pre"> </span>
<span style="white-space:pre"> </span>a = (CheckBox)findViewById(R.id.checkBox1);
<span style="white-space:pre"> </span>b = (CheckBox)findViewById(R.id.checkBox2);
<span style="white-space:pre"> </span>c = (CheckBox)findViewById(R.id.checkBox3);
<span style="white-space:pre"> </span>d = (CheckBox)findViewById(R.id.checkBox4);
<span style="white-space:pre"> </span>
<span style="white-space:pre"> </span>CheckListener checklistener = new CheckListener();
<span style="white-space:pre"> </span>d.setOnCheckedChangeListener(checklistener);
<span style="white-space:pre"> </span>
<span style="white-space:pre"> </span>
<span style="white-space:pre"> </span>
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>@Override
<span style="white-space:pre"> </span>public boolean onCreateOptionsMenu(Menu menu) {
<span style="white-space:pre"> </span>// Inflate the menu; this adds items to the action bar if it is present.
<span style="white-space:pre"> </span>getMenuInflater().inflate(R.menu.main, menu);
<span style="white-space:pre"> </span>return true;
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>class CheckListener implements OnCheckedChangeListener{
<span style="white-space:pre"> </span>@Override
<span style="white-space:pre"> </span>public void onCheckedChanged(CompoundButton buttonView,<span style="white-space:pre"> </span>boolean isChecked) {
<span style="white-space:pre"> </span>
<span style="white-space:pre"> </span>
<span style="white-space:pre"> </span>a.setChecked(isChecked);
<span style="white-space:pre"> </span>b.setChecked(isChecked);
<span style="white-space:pre"> </span>c.setChecked(isChecked);
<span style="white-space:pre"> </span>
<span style="white-space:pre"> </span>
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>
<span style="white-space:pre"> </span>
<span style="white-space:pre"> </span>
<span style="white-space:pre"> </span>