Android学习之路UI控件——3、RadioButton
来源:互联网 发布:adb强制安装软件 编辑:程序博客网 时间:2024/05/11 04:40
RadioButton表示单个单选框,而RadioGroup是可以容纳多个RadioButton的容器组件,每个RadioGroup中的RadioButton同时只能有一个被选中,group里面可以用android:checked=”true”表示默认选中,一般放在RadioGroup的起始位置。
本例欲实现如图示功能
下面代码为RadioButton的XML文档
<?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" > <RadioGroup android:id="@+id/radg_1" android:layout_width="wrap_content" android:layout_height="wrap_content" > <RadioButton android:id="@+id/radi_man" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="大专" /> <RadioButton android:id="@+id/radi_woman" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="本科" /> <RadioButton android:id="@+id/radi_other" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="硕士" /> </RadioGroup></LinearLayout>
下面代码为主程序代码
package com.example;import android.app.Activity;import android.os.Bundle;import android.widget.RadioButton;import android.widget.RadioGroup;import android.widget.Toast;import android.widget.RadioGroup.OnCheckedChangeListener;public class RadioActivity extends Activity { RadioGroup radioGroup; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.layout_radio); radioGroup = (RadioGroup) findViewById(R.id.radg_1); radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { RadioButton r = (RadioButton) RadioActivity.this.findViewById(checkedId); Toast.makeText(getApplicationContext(), r.getText() + "---checkedId:" + checkedId, Toast.LENGTH_LONG).show(); } }); }}
0 0
- Android学习之路UI控件——3、RadioButton
- UI控件学习之CheckBox & RadioButton
- Android UI控件之RadioGroup、RadioButton
- Android UI设计——RadioButton和CheckBox控件
- Android UI 设计——RadioButton 和 CheckBox 控件
- Android UI基础——CheckBox&RadioButton控件
- Android UI学习之RadioButton和RadioGroup
- Android学习之路UI控件——2、CkeckBox
- Android学习-常见的UI控件 RadioGroup和RadioButton
- 【android基础学习之三】——基础控件Toast,EditText,RadioGroup,RadioButton
- Android UI开发之RadioButton
- Android UI学习笔记 之RadioButton和CheckBox的使用
- android学习之RadioButton
- Android 控件开发之 RadioButton
- android控件之radiobutton checkbox
- android自定义控件之radioButton
- android 控件之RadioGroup&RadioButton
- Android 控件开发之 RadioButton
- 原来是这样--游戏中那些所谓的“吃掉”
- 提高web应用性能之JavaScript性能调优
- UItextfield的一些方法总结
- PHP实现quicksort
- HDU2048
- Android学习之路UI控件——3、RadioButton
- Unity3D之如何将包大小减少到极致
- LeetCode 99: Recover Binary Search Tree
- Miller_rabin素数检验[HDU5391]
- 周记——20151026
- C语言实验——Hello World!(printf练习)
- jQuery学习之旅 Item7 区别this和$(this)
- KMP(未测试)
- Eclipse黑色背景保护眼睛设置分享