国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android編程實現變化的雙重選擇框功能示例

2019-12-12 01:47:40
字體:
來源:轉載
供稿:網友

本文實例講述了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程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 潜山县| 天祝| 惠水县| 保定市| 稻城县| 颍上县| 岳阳县| 喀什市| 绥滨县| 平塘县| 三都| 玛沁县| 丁青县| 玉林市| 松桃| 甘孜县| 马山县| 靖安县| 新余市| 龙海市| 屏边| 门头沟区| 张家口市| 宁乡县| 神木县| 铜山县| 无为县| 汤原县| 安福县| 洛阳市| 兴国县| 柳河县| 开鲁县| 台北县| 蓬安县| 广宗县| 湖口县| 普兰店市| 玉树县| 三穗县| 鹤庆县|