android中控件RadioButton的使用
来源:互联网 发布:阿里云 物联网 收入 编辑:程序博客网 时间:2024/04/29 11:57
在layout的activity_main.xml中
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="请选择国籍:" />
<RadioGroup
android:id="@+id/rg"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RadioButton
android:id="@+id/china"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="中国" />
<RadioButton
android:id="@+id/america"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="美国" />
<RadioButton
android:id="@+id/japan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="日本" />
</RadioGroup>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="click"
android:text="查看" >
</Button>
在MainActivity.java中
private RadioGroup rg ;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);rg = (RadioGroup) findViewById(R.id.rg) ;rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(RadioGroup group, int checkedId) {//希望弹出来选中项的文本RadioButton rb = (RadioButton) findViewById(checkedId) ;Toast.makeText(MainActivity.this, rb.getText(), 0).show() ;}}) ;}public void click(View view){//拿到选中项的idint id = rg.getCheckedRadioButtonId() ;//判断id是谁switch (id) {case R.id.china:Toast.makeText(MainActivity.this, "你点击的是:中国" , 0).show() ;break;case R.id.america:Toast.makeText(MainActivity.this, "你点击的是:美国" , 0).show() ;break;case R.id.japan:Toast.makeText(MainActivity.this, "你点击的是:日本" , 0).show() ;break;}}
- android中控件RadioButton的使用
- Android中RadioButton的使用
- Android开发中单选框控件RadioButton的使用
- Android之RadioButton控件使用
- android中checkbox和radiobutton的使用
- Android中RadioButton和Checkbox的使用
- Android开发--RadioButton和CheckBox控件的使用
- android 常用控件之 (RadioButton) 的使用
- Android 基本控件的使用三(RadioButton)
- Android控件系列之RadioButton与RadioGroup的基本使用
- Android控件之Button,RadioButton,CheckBox,DatePicker,DatePickerDialog的使用
- Android控件中CheckBox、RadioButton详解
- asp.net的RadioButton控件的使用
- android中RadioButton的学习
- android中RadioButton的选择器
- Android组件的使用:RadioButton
- VC中radiobutton控件的用法
- VC中radiobutton控件的用法
- 拓扑排序 hihoCoder1175 拓扑排序·二
- OutLook收件自动存储到指定文件夹
- android通过xutils上传图片。通过apx.net接收问题
- poj1837 Balance
- 优秀文章的链接
- android中控件RadioButton的使用
- start_kernel——boot_init_stack_canary
- Bioinformatics: Sequencing Antibiotics (week 3-4)
- Spring Mvc web.xml中设置了字符编码,中文依旧乱码
- 树状结构在关系型数据库的存储
- 华为机试OJ1
- HBase协处理器及实例
- Rock, Scissors, Paper(模拟)
- 数学之美笔录(2):中文分词