Android編程雙重單選對(duì)話(huà)框布局實(shí)現(xiàn)與事件監(jiān)聽(tīng)方法示例
本文實(shí)例講述了Android編程雙重單選對(duì)話(huà)框布局實(shí)現(xiàn)與事件監(jiān)聽(tīng)方法。分享給大家供大家參考,具體如下:
首先是自定義XML布局代碼:
<?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="@dimen/dialog" > <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/choice1" 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="@string/kind" android:id="@+id/radio1" android:checked="true" /> <RadioButton android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/attribute" android:id="@+id/radio2"/> </RadioGroup> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/choice2" 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="@string/area" android:id="@+id/radio3" android:checked="true"/> <RadioButton android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/count" android:id="@+id/radio4"/> </RadioGroup> </LinearLayout>
效果圖如下
引用布局的對(duì)話(huà)框和監(jiān)聽(tīng)如下:
LayoutInflater layoutInflater = LayoutInflater.from(MainPlan.this); View self = layoutInflater.inflate(R.layout.multichoicedialog, null);//引入對(duì)話(huà)框布局 final RadioGroup radioGroup1 = (RadioGroup) self.findViewById(R.id.radiogroup1); final RadioGroup radioGroup2 = (RadioGroup) self.findViewById(R.id.radiogroup2); new AlertDialog.Builder(MainPlan.this)//MainPlan是當(dāng)前activity .setView(self) .setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { dialog.dismiss(); } }) .setPositiveButton("確定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (radioGroup1.getCheckedRadioButtonId() == R.id.radio1) { if (radioGroup2.getCheckedRadioButtonId() == R.id.radio3) { } else {//處理各種事件 } } else { if (radioGroup2.getCheckedRadioButtonId() == R.id.radio3) { } else { } } } }) .show();
運(yùn)行之后的圖如下所示
更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專(zhuān)題:《Android開(kāi)發(fā)入門(mén)與進(jìn)階教程》、《Android調(diào)試技巧與常見(jiàn)問(wèn)題解決方法匯總》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》及《Android控件用法總結(jié)》
希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。
- Android studio自定義對(duì)話(huà)框效果
- Android?studio實(shí)現(xiàn)單選按鈕
- Android使用AlertDialog實(shí)現(xiàn)的信息列表單選、多選對(duì)話(huà)框功能
- Android實(shí)現(xiàn)單選與多選對(duì)話(huà)框的代碼
- Android中創(chuàng)建對(duì)話(huà)框(確定取消對(duì)話(huà)框、單選對(duì)話(huà)框、多選對(duì)話(huà)框)實(shí)例代碼
- Android單選按鈕對(duì)話(huà)框用法實(shí)例分析
- Android Studio實(shí)現(xiàn)單選對(duì)話(huà)框
相關(guān)文章
Android開(kāi)發(fā)實(shí)現(xiàn)的幾何圖形工具類(lèi)GeometryUtil完整實(shí)例
這篇文章主要介紹了Android開(kāi)發(fā)實(shí)現(xiàn)的幾何圖形工具類(lèi)GeometryUtil,涉及Android坐標(biāo)圖形數(shù)值運(yùn)算相關(guān)操作技巧,需要的朋友可以參考下2017-11-11Android自定義Drawable實(shí)現(xiàn)圓形和圓角
這篇文章主要為大家詳細(xì)介紹了Android自定義Drawable實(shí)現(xiàn)圓形和圓角,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-09-09Android網(wǎng)絡(luò)技術(shù)HttpURLConnection詳解
這篇文章主要為大家詳細(xì)介紹了Android網(wǎng)絡(luò)技術(shù)HttpURLConnection的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-07-07Android采用File形式保存與讀取數(shù)據(jù)的方法
這篇文章主要介紹了Android采用File形式保存與讀取數(shù)據(jù)的方法,涉及Android文件流操作的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2016-06-06Android自定義PopupWindow仿點(diǎn)擊彈出分享功能
這篇文章主要為大家詳細(xì)介紹了Android自定義PopupWindow仿點(diǎn)擊彈出分享功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-02-02Android中Glide加載到RelativeLayout背景圖方法示例
Glide框架大家應(yīng)該都很熟悉,我們可以使用Glide加載網(wǎng)絡(luò)圖片、加載gif圖片,使用簡(jiǎn)單。下面這篇文章主要給大家介紹了關(guān)于Android中Glide加載到RelativeLayout背景圖的相關(guān)資料,需要的朋友可以參考下。2017-12-12Win10下Android App安裝配置開(kāi)發(fā)環(huán)境
這篇文章主要為大家詳細(xì)介紹了Win10下Android App安裝配置開(kāi)發(fā)環(huán)境,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-07-07