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

首頁 > 系統(tǒng) > Android > 正文

Android編程雙重單選對話框布局實(shí)現(xiàn)與事件監(jiān)聽方法示例

2019-10-22 18:24:43
字體:
供稿:網(wǎng)友

本文實(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>

效果圖如下

Android,雙重單選對話框,布局,事件監(jiān)聽

引用布局的對話框和監(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)行之后的圖如下所示

Android,雙重單選對話框,布局,事件監(jiān)聽

 

希望本文所述對大家Android程序設(shè)計(jì)有所幫助。


注:相關(guān)教程知識閱讀請移步到Android開發(fā)頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 抚顺市| 嘉义县| 林芝县| 偏关县| 辛集市| 彩票| 桃江县| 巴彦淖尔市| 建湖县| 项城市| 南江县| 澎湖县| 洱源县| 百色市| 泌阳县| 澎湖县| 广饶县| 河曲县| 岳阳县| 卢龙县| 炎陵县| 肃宁县| 阳信县| 甘谷县| 阿克苏市| 文登市| 临潭县| 衡水市| 阳东县| 雅江县| 桐乡市| 会理县| 柳江县| 合江县| 东平县| 盐亭县| 米林县| 防城港市| 新津县| 三河市| 阿勒泰市|