RadioGroup的多行显示RadioButton
2016-04-06 12:51
411 查看
首先布局:布局为一个竖向的Linearlayout里放两个RadioGroup,如下
其次是Activity的核心代码:如下(isSelect是定义的一个全局布尔变量,初始为false)
如此,便可达到RadioGroup的多行显示了,今天的收获希望对大家有用,这也是我的第一篇博客,希望以后有更多的好资源和大家分享。。。。
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:layout_marginLeft="20dp" android:orientation="vertical" android:id="@id/move_radio"> <RadioGroup android:id="@+id/radiogroup1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal"> <RadioButton android:id="@+id/rbPack" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="包装ffff" /> <RadioButton android:id="@+id/rbBulk" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="散装dddd" /> <RadioButton android:id="@+id/rbStorageWayOther" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="其它ddd" /> </RadioGroup> <RadioGroup android:id="@+id/radiogroup2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal"> <RadioButton android:id="@+id/rbPack1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="港到门" /> <RadioButton android:id="@+id/rbBulk1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="门到港" /> <RadioButton android:id="@+id/rbStorageWayOther1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="门到门" /> </RadioGroup> </LinearLayout>
其次是Activity的核心代码:如下(isSelect是定义的一个全局布尔变量,初始为false)
@Override public void onCheckedChanged(RadioGroup group, int checkedId) { switch (group.getId()){ case R.id.radiogroup1: if (group != null && checkedId > -1 && !isSelect){ isSelect = true; radioGroup2.clearCheck(); isSelect = false; //获取变更后的选中项的ID int radioButtonId = group.getCheckedRadioButtonId(); //根据ID获取RadioButton的实例 RadioButton rb = (RadioButton)v.findViewById(radioButtonId); System.out.println("---text: "+rb.getText()); } break; case R.id.radiogroup2: if (group != null && checkedId > -1 && !isSelect){ isSelect = true; radioGroup1.clearCheck(); isSelect = false; //获取变更后的选中项的ID int radioButtonId = group.getCheckedRadioButtonId(); //根据ID获取RadioButton的实例 RadioButton rb = (RadioButton)v.findViewById(radioButtonId); System.out.println("---text: "+rb.getText()); } break; } }
如此,便可达到RadioGroup的多行显示了,今天的收获希望对大家有用,这也是我的第一篇博客,希望以后有更多的好资源和大家分享。。。。
相关文章推荐
- vs2013+cuda7.5+opencv3.1 将cu文件加入opencv工程问题记录
- Gremlin实现分析
- Android Studio ndk-Jni开发详细入门,Aes加密demo
- CCF 网络延时
- HTML4 和 HTML5 的10个关键区别
- iOS Xib关联错误导致的问题
- HDFS读写过程
- C#界面设计之谷歌地图下载并分块
- C++ 类的静态成员用法
- 7、大型重构
- C语言 32/64位机 数据类型字长
- avalon1与avalon2的异同点
- Redis命令-有序集合-zcard
- kvm快照功能
- 决心书
- centos6.4下配置nginx服务器更改根目录
- 剑指Offer-二维数组中的查找
- 算法_动态规划_电路布线
- 多层神经网络和BP反向传播算法Multilayer Networks and Backpropagation
- 神经网络Momentum