欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時(shí)間:2017年10月27日 11:08:55   作者:GISuuser  
這篇文章主要介紹了Android編程雙重單選對(duì)話(huà)框布局實(shí)現(xiàn)與事件監(jiān)聽(tīng)方法,涉及Android雙重單選對(duì)話(huà)框的界面布局與事件監(jiān)聽(tīng)、響應(yīng)等相關(guān)操作技巧,需要的朋友可以參考下

本文實(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ì)有所幫助。

相關(guān)文章

最新評(píng)論