Android编程双重单选对话框布局实现与事件监听方法示例
2017-10-27 11:08
781 查看
本文实例讲述了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程序设计有所帮助。
您可能感兴趣的文章:
- Android单选按钮对话框用法实例分析
- Android中创建对话框(确定取消对话框、单选对话框、多选对话框)实例代码
- Android使用AlertDialog实现的信息列表单选、多选对话框功能
- Android实现单选与多选对话框的代码
- Android中自定义对话框(Dialog)的实例代码
- 实例详解Android自定义ProgressDialog进度条对话框的实现
- Android中AlertDialog各种对话框的用法实例详解
- Android实现底部对话框BottomDialog弹出实例代码
- Android加载对话框同时异步执行实现方法
- 8种android 对话框(Dialog)使用方法详解
- Android中创建一个透明的进度对话框实例
相关文章推荐
- Android编程实现Toast自定义布局简单示例
- Android开发之布局文件中实现OnClick事件关联处理方法
- Android开发之布局文件里实现OnClick事件关联处理方法
- Android双重单选对话框的制作与监听
- Android TextView实现带链接文字事件监听的三种常用方式示例
- android三种方法实现监听事件
- Android编程实现在自定义对话框中获取EditText中数据的方法
- Android编程使用GestureDetector实现简单手势监听与处理的方法
- Android编程实现保存图片到系统图库的方法示例
- Android 实现事件监听的两个方法
- Android中GridView布局实现整体居中方法示例
- Android开发实现Fragment监听返回键事件功能的方法
- Android编程实现自定义Dialog的大小自动控制方法示例
- Android开发之Button事件实现与监听方法总结
- Android编程实现EditText字数监听并显示的方法
- Android编程实现随机生成颜色的方法示例
- 巧用布局文件实现Android中实现事件监听机制
- Android编程实现对话框Dialog背景透明功能示例
- Android编程使用android-support-design实现MD风格对话框功能示例
- android dialog 原来dialog对话框也有自己的按键监听事件 onKeyDown方法