Android编程实现变化的双重选择框功能示例

 更新时间:2017年10月27日 10:46:22   作者:GISuuser  
这篇文章主要介绍了Android编程实现变化的双重选择框功能,结合实例形式分析了Android双重选择框功能的样式布局与功能实现技巧,需要的朋友可以参考下

本文实例讲述了Android编程实现变化的双重选择框功能。分享给大家供大家参考,具体如下:

原理:定义四个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简单实现启动画面的方法

    这篇文章主要介绍了Android简单实现启动画面的方法,结合实例形式分析了启动画面核心代码及相关函数,具有一定参考借鉴价值,需要的朋友可以参考下
    2016-07-07
  • Android中Snackbar的使用方法及小技巧

    Android中Snackbar的使用方法及小技巧

    这篇文章主要给大家介绍了关于Android中Snackbar的使用方法及小技巧的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面来一起学习学习吧。
    2018-03-03
  • Android编程之图片相关代码集锦

    Android编程之图片相关代码集锦

    这篇文章主要介绍了Android编程之图片相关代码集锦,实例总结了大量Android图片操作相关代码,具有一定参考借鉴价值,需要的朋友可以参考下
    2015-11-11
  • Android 实现圆圈扩散水波动画效果两种方法

    Android 实现圆圈扩散水波动画效果两种方法

    这篇文章主要介绍了Android 实现圆圈扩散水波动画效果两种方法,需要的朋友可以参考下
    2018-05-05
  • 通过源码角度看看AccessibilityService

    通过源码角度看看AccessibilityService

    这篇文章主要给大家介绍了关于通过源码角度看看AccessibilityService的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2018-06-06
  • android如何改变editText控件中部分文字的格式

    android如何改变editText控件中部分文字的格式

    本文主要介绍了android改变editText控件中部分文字格式的方法,具有很好的参考价值。下面跟着小编一起来看下吧
    2017-03-03
  • Android实现文字翻转动画的效果

    Android实现文字翻转动画的效果

    本文实现了Android程序文字翻转动画的实现,具有一定的参考价值,有需要的朋友可以了解一下。
    2016-10-10
  • Android 自定义View 密码框实例代码

    Android 自定义View 密码框实例代码

    这篇文章主要介绍了Android 自定义View 密码框实例代码的相关资料,非常不错具有参考借鉴价值,需要的朋友可以参考下
    2016-06-06
  • Android版音乐播放器

    Android版音乐播放器

    这篇文章主要为大家详细介绍了Android版音乐播放器的实现方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2018-05-05
  • Android基于OpenCV实现Harris角点检测

    Android基于OpenCV实现Harris角点检测

    角点就是极值点,即在某方面属性特别突出的点。当然,你可以自己定义角点的属性(设置特定熵值进行角点检测)。角点可以是两条线的交叉处,也可以是位于相邻的两个主要方向不同的事物上的点。本文介绍如何基于OpenCV实现Harris角点检测
    2021-06-06

最新评论