Android編程實(shí)現(xiàn)變化的雙重選擇框功能示例
本文實(shí)例講述了Android編程實(shí)現(xiàn)變化的雙重選擇框功能。分享給大家供大家參考,具體如下:
原理:定義四個(gè)RadioGroup,通過(guò)第一個(gè)RadioGroup的選擇來(lái)控制其余幾個(gè)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="請(qǐng)選擇圖層" 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="永順鎮(zhèn)規(guī)劃圖" android:id="@+id/radi1" android:checked="true" /> <RadioButton android:layout_width="match_parent" android:layout_height="wrap_content" android:text="永順鎮(zhèn)權(quán)屬" android:id="@+id/radi2"/> <RadioButton android:layout_width="match_parent" android:layout_height="wrap_content" android:text="永順鎮(zhèn)現(xiàn)狀" 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="地塊編號(hào)" android:id="@+id/a1" android:checked="true"/> <RadioButton android:layout_width="match_parent" android:layout_height="wrap_content" android:text="用地性質(zhì)" 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="權(quán)屬性質(zhì)" 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="地類號(hào)" android:id="@+id/c2"/> <RadioButton android:layout_width="match_parent" android:layout_height="wrap_content" android:text="圖斑號(hào)" android:id="@+id/c3"/> </RadioGroup> <AutoCompleteTextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="請(qǐng)輸入查詢內(nèi)容" 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; } } });
效果圖:
更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android開(kāi)發(fā)入門與進(jìn)階教程》、《Android調(diào)試技巧與常見(jiàn)問(wèn)題解決方法匯總》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》及《Android控件用法總結(jié)》
希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。
相關(guān)文章
android編程實(shí)現(xiàn)對(duì)話框的封裝實(shí)例
這篇文章主要介紹了android編程實(shí)現(xiàn)對(duì)話框的封裝,以實(shí)例形式分析了Android針對(duì)對(duì)話框的相關(guān)操作技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-11-11Android實(shí)現(xiàn)錄音監(jiān)聽(tīng)動(dòng)畫的示例代碼
在很多app種內(nèi)置了語(yǔ)音助手,也存在各種動(dòng)畫,這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)錄音監(jiān)聽(tīng)動(dòng)畫的示例代碼,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2023-12-12Android應(yīng)用程序模型之應(yīng)用程序,任務(wù),進(jìn)程,線程分析
這篇文章主要介紹了Android應(yīng)用程序模型之應(yīng)用程序,任務(wù),進(jìn)程,線程分析,較為詳細(xì)的分析了Android應(yīng)用程序模型中關(guān)于任務(wù)、進(jìn)程、線程的相關(guān)概念及注意事項(xiàng),需要的朋友可以參考下2016-01-01ReactNative (API)AsyncStorage存儲(chǔ)詳解及實(shí)例
這篇文章主要介紹了ReactNative (API)AsyncStorage存儲(chǔ)詳解及實(shí)例的相關(guān)資料,需要的朋友可以參考下2016-10-10android開(kāi)發(fā)之方形圓角listview代碼分享
我寫這篇文章受到了kiritor的專欄發(fā)表的博文Android UI控件之ListView實(shí)現(xiàn)圓角效果的啟發(fā)。2013-06-06Android studio 生成帶Kotlin文檔的實(shí)現(xiàn)方式
這篇文章主要介紹了Android studio 生成帶Kotlin文檔的實(shí)現(xiàn)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-03-03Android控件之ImageView用法實(shí)例分析
這篇文章主要介紹了Android控件之ImageView用法,以實(shí)例形式較為詳細(xì)的分析了ImageView控件用于顯示圖片的使用方法,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-09-09Android中SharedPreferences簡(jiǎn)單使用實(shí)例
這篇文章主要介紹了Android中SharedPreferences簡(jiǎn)單使用案例,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-10-10Android中的動(dòng)態(tài)加載機(jī)制的學(xué)習(xí)研究
本篇文章主要介紹了Android中的動(dòng)態(tài)加載機(jī)制,對(duì)android項(xiàng)目開(kāi)發(fā)有著一定的幫助,有興趣的同學(xué)可以了解一下。2016-11-11Android?Studio實(shí)現(xiàn)簡(jiǎn)單頁(yè)面跳轉(zhuǎn)的詳細(xì)教程
這篇文章主要給大家介紹了關(guān)于Android?Studio實(shí)現(xiàn)簡(jiǎn)單頁(yè)面跳轉(zhuǎn)的詳細(xì)教程,文中通過(guò)圖文介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用Android?Studio具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2023-01-01