CheckBox01.JAVA:
package com.CheckBox01;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.CompoundButton.OnCheckedChangeListener;
public class CheckBox01 extends Activity {
private TextView mTextView;
private Button mButton;
private CheckBox mCB1,mCB2,mCB3,mCB4;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mTextView=(TextView)findViewById(R.id.mTextView);
mButton=(Button)findViewById(R.id.mButton);
mCB1=(CheckBox)findViewById(R.id.mCB1);
mCB2=(CheckBox)findViewById(R.id.mCB2);
mCB3=(CheckBox)findViewById(R.id.mCB3);
mCB4=(CheckBox)findViewById(R.id.mCB4);
mCB1.setOnCheckedChangeListener(new OnCheckedChangeListener(){
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked){
if(mCB1.isChecked()){
DisplayToast("you choose:"+mCB1.getText());
}
}
});
mCB2.setOnCheckedChangeListener(new OnCheckedChangeListener(){
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked){
if(mCB2.isChecked()){
DisplayToast("you choose:"+mCB2.getText());
}
}
});
mCB3.setOnCheckedChangeListener(new OnCheckedChangeListener(){
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked){
if(mCB3.isChecked()){
DisplayToast("you choose:"+mCB3.getText());
}
}
});
mCB4.setOnCheckedChangeListener(new OnCheckedChangeListener(){
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked){
if(mCB4.isChecked()){
DisplayToast("you choose:"+mCB4.getText());
}
}
});
mButton.setOnClickListener(new OnClickListener(){
public void onClick(View v){
if(mCB1.isChecked()&&mCB2.isEnabled()){
DisplayToast("GOOD!!!!");
}
}
});
}
public void DisplayToast(String str){
Toast toast=Toast.makeText(this, str, Toast.LENGTH_SHORT);
toast.show();
}
}
main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/mTextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<Button
android:id="@+id/mButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/mButton"
/>
<CheckBox
android:id="@+id/mCB1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/mCB1"
/>
<CheckBox
android:id="@+id/mCB2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/mCB2"
/>
<CheckBox
android:id="@+id/mCB3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/mCB3"
/>
<CheckBox
android:id="@+id/mCB4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/mCB4"
/>
</LinearLayout>
AndroidMainfest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.CheckBox01"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".CheckBox01"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>