Android编程实现变化的双重选择框功能示例
2017-10-27 10:46
946 查看
原理:定义四个RadioGroup,通过第一个RadioGroup的选择来控制其余几个radiogroup的显隐
布局:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:padding="20dp"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="请选择图层" android:textColor="@color/green" android:textSize="@dimen/text"/> <RadioGroup android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/radiogroup1"> <RadioButton android:layout_width="match_parent" android:layout_height="wrap_content" android:text="永顺镇规划图" android:id="@+id/radi1" android:checked="true" /> <RadioButton android:layout_width="match_parent" android:layout_height="wrap_content" android:text="永顺镇权属" android:id="@+id/radi2"/> <RadioButton android:layout_width="match_parent" android:layout_height="wrap_content" android:text="永顺镇现状" android:id="@+id/radi3"/> </RadioGroup> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="选择查询字段" android:textColor="@color/green" android:textSize="@dimen/text"/> <RadioGroup android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/radiogroup2"> <RadioButton android:layout_width="match_parent" android:layout_height="wrap_content" android:text="地块编号" android:id="@+id/a1" android:checked="true"/> <RadioButton android:layout_width="match_parent" android:layout_height="wrap_content" android:text="用地性质" android:id="@+id/a2"/> <RadioButton android:layout_width="match_parent" android:layout_height="wrap_content" android:text="用地分类" android:id="@+id/a3"/> </RadioGroup> <RadioGroup android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/radiogroup3" android:visibility="gone"> <RadioButton android:layout_width="match_parent" android:layout_height="wrap_content" android:text="权属性质" android:id="@+id/b1" android:checked="true"/> </RadioGroup> <RadioGroup android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/radiogroup4" android:visibility="gone"> <RadioButton android:layout_width="match_parent" android:layout_height="wrap_content" android:text="用地类别" android:id="@+id/c1" android:checked="true"/> <RadioButton android:layout_width="match_parent" android:layout_height="wrap_content" android:text="地类号" android:id="@+id/c2"/> <RadioButton android:layout_width="match_parent" android:layout_height="wrap_content" android:text="图斑号" android:id="@+id/c3"/> </RadioGroup> <AutoCompleteTextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="请输入查询内容" android:id="@+id/autoCompleteTextView" /> </LinearLayout>
java代码:
LayoutInflater layoutInflater=LayoutInflater.from(MainPlan.this); View self=layoutInflater.inflate(R.layout.thiswindow, null); final RadioGroup radioGroup1 = (RadioGroup) self.findViewById(R.id.radiogroup1); final RadioGroup radioGroup2 = (RadioGroup) self.findViewById(R.id.radiogroup2); final RadioGroup radioGroup3 = (RadioGroup) self.findViewById(R.id.radiogroup3); final RadioGroup radioGroup4 = (RadioGroup) self.findViewById(R.id.radiogroup4); radioGroup1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { switch (checkedId){ case R.id.radi1: radioGroup2.setVisibility(View.VISIBLE); radioGroup3.setVisibility(View.GONE); radioGroup4.setVisibility(View.GONE); break; case R.id.radi2: radioGroup2.setVisibility(View.GONE); radioGroup3.setVisibility(View.VISIBLE); radioGroup4.setVisibility(View.GONE);break; case R.id.radi3: radioGroup2.setVisibility(View.GONE); radioGroup3.setVisibility(View.GONE); radioGroup4.setVisibility(View.VISIBLE);break; default:break; } } });
效果图:
更多关于Android相关内容感兴趣的读者可查看本站专题:《Android开发入门与进阶教程》、《Android调试技巧与常见问题解决方法汇总》、《Android基本组件用法总结》、《Android视图View技巧总结》、《Android布局layout技巧总结》及《Android控件用法总结》
希望本文所述对大家Android程序设计有所帮助。
您可能感兴趣的文章:
相关文章推荐
- Android编程实现的首页左右滑动切换功能示例
- Android编程实现对话框Dialog背景透明功能示例
- Android编程实现点击链接打开APP功能示例
- Android编程双重单选对话框布局实现与事件监听方法示例
- Android编程实现自定义title功能示例
- Android编程实现的自定义弹窗(PopupWindow)功能示例
- Android编程实现自定义输入法功能示例【输入密码时防止第三方窃取】
- Android编程实现扭曲图像的绘制功能示例
- Android编程实现通讯录中联系人的读取,查询,添加功能示例
- Android编程实现图片的上传和下载功能示例
- Android编程实现两点触控功能示例
- Android编程实现ListView滚动提示等待框功能示例
- Android编程实现的简易路径导航条功能示例
- Android编程实现通讯录中联系人的读取,查询,添加功能示例
- Android编程实现对电池状态的监视功能示例
- Android编程实现对话框形式进度条功能示例
- Android编程基于自定义View实现绚丽的圆形进度条功能示例
- Android编程使用Service实现Notification定时发送功能示例
- Android编程实现长按Button按钮连续响应功能示例
- Android编程使用android-support-design实现MD风格对话框功能示例