Android RadioGroup控件的使用
来源:互联网 发布:ubuntu ssh有安装包吗 编辑:程序博客网 时间:2024/06/15 07:39
在Android开发过程中,我们经常要使用RadioGroup控件,用于支持单项或者多项选择,今天写了一个RadioGroup的例子,贴出来作为自己学习的记录,如果对大家有帮助就更好了,在例子中,我们选择电影类型,然后在一个TextView中展示选择的结果。
1. RadioGroupActivity
控件所在的活动的Activity,包含一个RadioGroup组和一个TextView
2.radio.xml
RadioGroupActivity的布局文件
RadioGroupActivity.java
package com.augmentum.example;import com.example.androidexample.R;import android.app.Activity;import android.os.Bundle;import android.widget.RadioButton;import android.widget.RadioGroup;import android.widget.TextView;public class RadioGroupActivity extends Activity {private RadioGroup radioGroup;private TextView textViewChoice;@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);setContentView(R.layout.radio);radioGroup=(RadioGroup)findViewById(R.id.radioGroup);textViewChoice = (TextView)findViewById(R.id.textViewChoice); radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { public void onCheckedChanged(RadioGroup group, int checkedId) { // checkedId is the RadioButton selected RadioButton rb=(RadioButton)findViewById(checkedId); textViewChoice.setText("You Selected "+rb.getText()); //Toast.makeText(getApplicationContext(), rb.getText(), Toast.LENGTH_SHORT).show(); } });}}
radio.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="#ffc5bdff"> <TextView android:id="@+id/textViewSelection" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Select your favoutire movie Genre" /> <RadioGroup android:id="@+id/radioGroup" android:layout_width="wrap_content" android:layout_height="wrap_content"> <RadioButton android:id="@+id/radioButtonActionMovies" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Action Movies" android:checked="false" /> <RadioButton android:id="@+id/radioButtonAnimationMovies" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Animation Movies" android:checked="false" /> <RadioButton android:id="@+id/radioButtonHorrorMovies" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Horror Movies" android:checked="false" /> <RadioButton android:id="@+id/radioButtonComedyMovies" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Comedy Movies" android:checked="false" /> <RadioButton android:id="@+id/radioButtonSciFiMovies" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Sci-Fi Movies" android:checked="false" /> </RadioGroup> <TextView android:id="@+id/textViewChoice" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="You Selected: " android:textStyle="bold"/></LinearLayout>
运行效果如下:
0 0
- Android RadioGroup控件的使用
- android RadioGroup的使用
- Android控件系列之RadioButton与RadioGroup的基本使用
- Android 多选一 RadioGroup的使用
- 控件RadioGroup、RadioButton和CheckBox的使用
- RadioGroup,RadioButton CheckBox控件的使用
- android控件07 RadioGroup
- Android控件RadioButton&RadioGroup
- Ext radiogroup控件使用
- (转)android常用控件(二) RadioGroup RadioButton CheckBox Toast的使用
- Android 基本控件的使用四(仿团购底部菜单App)(RadioGroup)
- Android之单选控件RadioGroup,RadioButton使用
- Android开发之RadioGroup与RadioButton控件使用
- Android PopupWindow RadioGroup RadioButton 的使用
- android学习笔记之RadioGroup的使用
- Android开发(20)--RadioGroup的使用
- Android—RadioGroup和RadioButton的使用
- Android开发笔记----radioGroup的使用
- 在Eclipse中运行hadoop程序
- 自适应肤色识别
- DFS非递归实现图的遍历
- WdatePicker 没有权限(IE下报错)
- python yield解读
- Android RadioGroup控件的使用
- 第16周项目3-用函数指针调用函数
- 单表查询如何建立索引让你的查询语句性能达到最高
- 64位Centos上编译php,GD库无jpeg支持
- CentOS安装+配置+远程
- jrebel问题
- 【笔记】Java编程思想——类型检查
- web测试入门该学习哪些内容?
- linux下如何以某个用户的身份运行程序