package cn.edu.checkbox;
import android.app.Activity;
import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
public class CheckBoxActivity extends Activity {
/** Called when the activity is first created. */
private CheckBox check1;
private CheckBox check2;
private CheckBox check3;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
check1=(CheckBox)this.findViewById(R.id.check1);
check2=(CheckBox)this.findViewById(R.id.check2);
check3=(CheckBox)this.findViewById(R.id.check3);
check1.setOnCheckedChangeListener(new OnCheckedChangeListener(){
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
// TODO Auto-generated method stub
System.out.println(isChecked);
}
});
}
}
布局文件中
<CheckBox android:id="@+id/check1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" />