一.思维导图
二.继承关系图
(1)单选按钮组
(2)单选按钮
(3)复选框
三.实例
(一)、运行效果
(二)实现步骤
1.创建安卓应用
2.布局资源文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingTop="30dp">
<TextView
android:id="@+id/tv_set_information"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="30dp"
android:text="@string/set_information"
android:textColor="#0000ff"
android:textSize="30sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/name"
android:textColor="#000000"
android:textSize="16sp" />
<EditText
android:id="@+id/edt_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="@string/input_name"
android:singleLine="true" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_gender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/gender"
android:textColor="#000000"
android:textSize="16sp" />
<RadioGroup
android:id="@+id/rg_gender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="@+id/rb_male"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="@string/male" />
<RadioButton
android:id="@+id/rb_female"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:text="@string/female" />
</RadioGroup>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_hobby"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hobby"
android:textColor="#000000"
android:textSize="16sp" />
<CheckBox
android:id="@+id/cb_music"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/music" />
<CheckBox
android:id="@+id/cb_read"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/read" />
<CheckBox
android:id="@+id/cb_food"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/food" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp">
<Button
android:id="@+id/btn_ok"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="doOK"
android:text="@string/ok" />
<Button
android:id="@+id/btn_clear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="doClear"
android:text="@string/clear" />
<Button
android:id="@+id/btn_exit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="doExit"
android:text="@string/exit" />
</LinearLayout>
<TextView
android:id="@+id/tv_result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:textSize="15sp" />
</LinearLayout>
3.字符串资源文件
<resources>
<string name="app_name">设置基本信息</string>
<string name="male">男</string>
<string name="female">女</string>
<string name="single">单身</string>
<string name="married">已婚</string>
<string name="music">音乐</string>
<string name="read">阅读</string>
<string name="food">美食</string>
<string name="ok">确定</string>
<string name="clear">清除</string>
<string name="exit">退出</string>
<string name="set_information">设置基本信息</string>
<string name="gender">性别:</string>
<string name="marriage">婚姻:</string>
<string name="hobby">爱好:</string>
<string name="name">姓名:</string>
<string name="input_name">请输入姓名</string>
</resources>
4,主界面
public class MainActivity extends Activity {
private EditText editText;
private TextView textView2;
private RadioGroup rgSingleChoice;
private RadioButton rbSingleA;
private RadioButton rbSingleB;
private CheckBox cbMultipleA;
private CheckBox cbMultipleB;
private CheckBox cbMultipleC;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editText = findViewById(R.id.edt_name);
textView2 = findViewById(R.id.tv_result);
rgSingleChoice = findViewById(R.id.rg_gender);
rbSingleA = findViewById(R.id.rb_male);
rbSingleB = findViewById(R.id.rb_female);
cbMultipleA = findViewById(R.id.cb_music);
cbMultipleB = findViewById(R.id.cb_read);
cbMultipleC = findViewById(R.id.cb_food);
}
public void Save(View view){
String s="性别:";
if(rbSingleA.isChecked()){
s+="男";
}else if(rbSingleB.isChecked()){
s+="女";
}
s+=" 爱好:";
if(cbMultipleA.isChecked()){
s+="音乐";
}
if(cbMultipleB.isChecked()){
s+="阅读";
}
if(cbMultipleC.isChecked()){
s+="美食";
}
textView2.setText(s);
}
public void doExit(View view){
finish();
}
}