【Android每日一讲】2012.11.27 向左或向右
来源:互联网 发布:.bat java 编辑:程序博客网 时间:2024/06/06 01:55
1. 范例说明
- 今天介绍RadioGroup的组事件。RadioGroup可将各自不同的RadioButton设限于同一个Radio按钮组,同属于一个RadioGroup组里的按钮,只能做出单一选择(单选题)。
- 该范例首先设计一个TextView Widget,以及一个RadioGroup,并于该RadioGroup内放置两个RadioButton,默认为都不选择,在程序运行阶段,利用onCheckedChanged作为启动事件装置,让User在选择其中一个按钮时,显示被选择的内容,最后将RadioButton的选项文字显示于TextView中。
2. 运行结果
3. 编写代码
/** Called when the activity is first created. */@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);/* 取得 TextView、RadioGroup、RadioButton对象 */mTextView1 = (TextView) findViewById(R.id.myTextView);mRadioGroup1 = (RadioGroup) findViewById(R.id.myRadioGroup);mRadio1 = (RadioButton) findViewById(R.id.myRadioButton1);mRadio2 = (RadioButton) findViewById(R.id.myRadioButton2);/* RadioGroup用OnCheckedChangeListener来执行 */mRadioGroup1.setOnCheckedChangeListener(mChangeRadio);}private RadioGroup.OnCheckedChangeListener mChangeRadio = new RadioGroup.OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(RadioGroup group, int checkedId) {// TODO Auto-generated method stubif (checkedId == mRadio1.getId()) {/* 把mRadio1的内容传到mTextView1 */mTextView1.setText(mRadio1.getText());} else if (checkedId == mRadio2.getId()) {/* 把mRadio2的内容传到mTextView1 */mTextView1.setText(mRadio2.getText());}}};
4. 扩展学习与作业
RadioGroup单选按钮用法
http://www.eyeandroid.com/thread-10158-1-1.html
作业:请试着在其中加一个Button,作为清除RadioButton的选择状态
5.视频讲解
http://www.eyeandroid.com/thread-10723-1-1.html
<script type="text/javascript"><!--google_ad_client = "ca-pub-1944176156128447";/* cnblogs 首页横幅 */google_ad_slot = "5419468456";google_ad_width = 728;google_ad_height = 90;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
- 【Android每日一讲】2012.11.27 向左或向右
- 程序员,向左或向右
- 向左向右?
- 向左?向右?
- 向左,向右
- android 使文字向左或者向右倾斜
- 【Android每日一讲】2012.11.19 我同意条款
- 【Android每日一讲】2012.11.26 消费券采购列表
- 4.6 向左或向右RadioGroup组与onCheckedChanged事件
- 【算法题】字符串向左或向右循环移动
- 4.6向左或向右 ---RadioGroup组与onCheckedChanged事件
- 图片查看器-向左 向右 切换图片或内容
- 鼠标经过箭头时,图片会向左或向右…
- ViewPager实现轮播图(可无限向左或向右滑动)
- BPM向左,工作流向右(一)什么是业务流程
- BPM向左,工作流向右(一)什么是业务流程
- 向左走,向右走
- 向左走,向右走
- c++创建对象的两种方式
- Serial Number Related Profiles/Options
- 常问的SSH面试题
- 线程中变量的作用范围
- a[i]-'0'
- 【Android每日一讲】2012.11.27 向左或向右
- C++实现数据结构四 单循环链表
- C语言指针和数组
- SVN使用说明
- struts2中的input标签
- [Android Samples视频系列之ApiDemos] App
- 线程
- 通过sql语句获得IP和主机名
- Apache的Order Allow,Deny 详解