怎么在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中实现一个双重选择框功能-创新互联
文章链接:https://www.cdcxhl.com/article48/cegdhp.html

成都网站建设公司_创新互联,为您提供微信小程序网站制作营销型网站建设定制网站网页设计公司关键词优化

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

成都网站建设公司