這期內容當中小編將會給大家帶來有關怎么在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中實現一個雙重選擇框功能-創新互聯
文章鏈接:http://www.yijiale78.com/article48/cegdhp.html
成都網站建設公司_創新互聯,為您提供微信小程序、網站制作、營銷型網站建設、定制網站、網頁設計公司、關鍵詞優化
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯