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布局控件View ViewRootImpl WindowManagerService关系

    Android布局控件View ViewRootImpl WindowManagerService关系

    这篇文章主要为大家介绍了Android布局控件View ViewRootImpl WindowManagerService关系示例解析,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2023-02-02
  • Android中RecyclerView 滑动时图片加载的优化

    Android中RecyclerView 滑动时图片加载的优化

    本篇文章主要介绍了Android中RecyclerView 滑动时图片加载的优化,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2017-04-04
  • Activity 四种启动模式详细介绍

    Activity 四种启动模式详细介绍

    这篇文章主要介绍了Activity 四种启动模式详细介绍的相关资料,需要的朋友可以参考下
    2017-02-02
  • Android UI设计与开发之ViewPager仿微信引导界面以及动画效果

    Android UI设计与开发之ViewPager仿微信引导界面以及动画效果

    这篇文章主要为大家详细介绍了Android UI设计与开发之ViewPager仿微信引导界面以及动画效果,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2017-08-08
  • Android DataBinding类关系深入探究

    Android DataBinding类关系深入探究

    看了谷歌官方文章确实写的太简略了,甚至看完之后有很多地方还不知道怎么回事儿或者怎么用,那么接下来我将通过文章全面介绍一下DataBinding类关系
    2022-11-11
  • AndroidX下使用Activity和Fragment的变化详解

    AndroidX下使用Activity和Fragment的变化详解

    这篇文章主要介绍了AndroidX下使用Activity和Fragment的变化详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2020-04-04
  • 基于Android代码实现常用布局

    基于Android代码实现常用布局

    大家在日常中经常见到用xml文件实现android常用布局,但是大家知道如何用代码实现呢?使用代码实现可以帮助我们学习sdk api,所以小编把我日常整理些关于android常用布局代码实现分享给大家
    2015-11-11
  • Android自定义WaveView实现波浪进度效果

    Android自定义WaveView实现波浪进度效果

    最近注意到百度外卖以及淘宝个人中心,都用到了类似水波起伏的效果,于是就参照网上的资料然后自己整改,自定义了一个waveView来实现这个效果,文中给出来详细的实现原理及实例代码,有需要的朋友们可以参考借鉴,下面来一起看看吧。
    2017-01-01
  • Android使用ContentProvider实现查看系统短信功能

    Android使用ContentProvider实现查看系统短信功能

    这篇文章主要为大家详细介绍了Android使用ContentProvider实现查看系统短信功能,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2021-11-11
  • Android搜索结果显示高亮实例(有数据滑动底部自动刷新)

    Android搜索结果显示高亮实例(有数据滑动底部自动刷新)

    本篇文章主要介绍了Android搜索结果显示高亮实例(有数据滑动底部自动刷新),非常具有实用价值,需要的朋友可以参考下
    2017-04-04

最新评论