RadioGroup的多行显示RadioButton
来源:互联网 发布:淘宝王府井网上商城 编辑:程序博客网 时间:2024/05/19 13:22
首先布局:布局为一个竖向的Linearlayout里放两个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)
@Overridepublic 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的多行显示了,今天的收获希望对大家有用,这也是我的第一篇博客,希望以后有更多的好资源和大家分享。。。。
0 0
- RadioGroup的多行显示RadioButton
- Android 动态生成 radiobutton 解决 radiogroup 多行显示的问题 单选
- RadioGroup RadioButton的Demo
- 可以解决RadioGroup中两个RadioButton选中以及RadioButton回行布局的RadioGroup
- RadioButton和CheckBox的区别,RadioButton&RadioGroup
- 自定义支持多行显示的RadioGroup
- RadioGroup的RadioButton不居中
- RadioGroup和RadioButton的实现
- RadioButton和RadioGroup的使用
- RadioGroup && RadioButton
- RadioGroup,RadioButton
- RadioButton&RadioGroup
- RadioGroup+RadioButton
- RadioButton&RadioGroup
- RadioButton+RadioGroup
- 可嵌套多层的radiobutton的radiogroup
- Android PopupWindow RadioGroup RadioButton 的使用
- android RadioGroup和RadioButton的用法
- Android学习笔记(Google官方教程)(一)
- Java 将字节数组转化为16进制的多种方案
- HDU 1272 小希的迷宫
- vs2013+cuda7.5+opencv3.1 将cu文件加入opencv工程问题记录
- Java多线程之实现方式
- RadioGroup的多行显示RadioButton
- Android中JNI学习博客
- 应用scikit-learn做文本分类
- sonar之个人实践
- Java环境变量的作用以及如何配置环境变量
- ONE·一个简单API
- LeetCode 239. Sliding Window Maximum(滑动窗口最大值)
- Result Maps collection already contains value 及无法找到Mapper.xml文件错误解决办法
- MySQL(5)-docker中安装和使用