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

首頁 > 系統 > Android > 正文

Android編程雙重單選對話框布局實現與事件監聽方法示例

2019-12-12 01:47:36
字體:
來源:轉載
供稿:網友

本文實例講述了Android編程雙重單選對話框布局實現與事件監聽方法。分享給大家供大家參考,具體如下:

首先是自定義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>

效果圖如下

引用布局的對話框和監聽如下:

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是當前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();

運行之后的圖如下所示

更多關于Android相關內容感興趣的讀者可查看本站專題:《Android開發入門與進階教程》、《Android調試技巧與常見問題解決方法匯總》、《Android基本組件用法總結》、《Android視圖View技巧總結》、《Android布局layout技巧總結》及《Android控件用法總結

希望本文所述對大家Android程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 牙克石市| 涪陵区| 铜鼓县| 山西省| 麟游县| 夏河县| 南安市| 扶绥县| 贺州市| 阿巴嘎旗| 桦南县| 即墨市| 钟山县| 马边| 靖边县| 钦州市| 防城港市| 和龙市| 浑源县| 台前县| 白河县| 阳谷县| 拉萨市| 汪清县| 灌南县| 郴州市| 萨迦县| 文化| 定兴县| 铁岭县| 桂阳县| 浏阳市| 民权县| 海宁市| 沙洋县| 垫江县| 崇州市| 蛟河市| 天长市| 岑巩县| 视频|