国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 赤城县| 竹山县| 绵阳市| 云林县| 青浦区| 寿阳县| 抚宁县| 莫力| 枣阳市| 舒城县| 漳浦县| 华容县| 花垣县| 太白县| 通州区| 太保市| 华容县| 七台河市| 铅山县| 泽州县| 中卫市| 邹平县| 桐城市| 基隆市| 云阳县| 辽中县| 越西县| 甘肃省| 高雄市| 清镇市| 深圳市| 武汉市| 尼玛县| 华亭县| 威远县| 锡林浩特市| 许昌市| 兰州市| 吴堡县| 邮箱| 静安区|