Android編程雙重單選對話框布局實(shí)現(xiàn)與事件監(jiān)聽方法示例
本文實(shí)例講述了Android編程雙重單選對話框布局實(shí)現(xiàn)與事件監(jiān)聽方法。分享給大家供大家參考,具體如下:
首先是自定義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>
效果圖如下
引用布局的對話框和監(jiān)聽如下:
LayoutInflater layoutInflater = LayoutInflater.from(MainPlan.this); View self = layoutInflater.inflate(R.layout.multichoicedialog, null);//引入對話框布局 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)容感興趣的讀者可查看本站專題:《Android開發(fā)入門與進(jìn)階教程》、《Android調(diào)試技巧與常見問題解決方法匯總》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》及《Android控件用法總結(jié)》
希望本文所述對大家Android程序設(shè)計(jì)有所幫助。
相關(guān)文章
Android開發(fā)實(shí)現(xiàn)的幾何圖形工具類GeometryUtil完整實(shí)例
這篇文章主要介紹了Android開發(fā)實(shí)現(xiàn)的幾何圖形工具類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圖片,使用簡單。下面這篇文章主要給大家介紹了關(guān)于Android中Glide加載到RelativeLayout背景圖的相關(guān)資料,需要的朋友可以參考下。2017-12-12Win10下Android App安裝配置開發(fā)環(huán)境
這篇文章主要為大家詳細(xì)介紹了Win10下Android App安裝配置開發(fā)環(huán)境,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-07-07