示例代码
package com.person.radiogrouptest;
import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
public class AtyUsingCheckBox extends Activity {
private CheckBox shuaige, meinv, renyao;
private Button regItem;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.aty_using_checkbox);
shuaige = (CheckBox) findViewById(R.id.shuaige);
meinv = (CheckBox) findViewById(R.id.meinv);
renyao = (CheckBox) findViewById(R.id.renyao);
regItem = (Button) findViewById(R.id.regitem);
regItem.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String str = "你的综合体是 : \n";
if (shuaige.isChecked()) {
str += "帅哥\n";
}
if (meinv.isChecked()) {
str += "美女\n";
}
if (renyao.isChecked()) {
str += "人妖\n";
}
new AlertDialog.Builder(AtyUsingCheckBox.this).setTitle("综合体是")
.setMessage(str).setPositiveButton("关闭", null).show();
}
});
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="你是谁?" />
<CheckBox
android:id="@+id/shuaige"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="帅哥?" />
<CheckBox
android:id="@+id/meinv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="美女?" />
<CheckBox
android:id="@+id/renyao"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="人妖?" />
<Button
android:id="@+id/regitem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="提交" />
</LinearLayout>
最后在manifest的xml文件中进行该Activity进行注册