Android如何实现双重单选对话框布局

发布时间:2021-08-06 13:41:03 作者:小新
来源:亿速云 阅读:135

这篇文章将为大家详细讲解有关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>

效果图如下

Android如何实现双重单选对话框布局

引用布局的对话框和监听如下:

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如何实现双重单选对话框布局”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。

推荐阅读:
  1. android实现综合布局
  2. Android布局

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

android

上一篇:易语言如何仿360悬浮窗实现流量监控和内存优化

下一篇:如何解决某些HTML字符打不出来的问题

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》