Android Dialog 简单封装
转载:https://www.cnblogs.com/zjjne/archive/2013/10/03/3350382.html
public class MyAlertDialog {
//region 确认/取消 弹出框
//取消按钮,默认canel
public static Dialog createConfirmDialog(Context context, String title, String message,
String positiveBtnName, String negativeBtnName, DialogInterface.OnClickListener positiveBtnListener) {
Dialog dialog = null;
AlertDialog.Builder builder = new AlertDialog.Builder(context);
//设置对话框标题
builder.setTitle(title);
//设置对话框消息
builder.setMessage(message);
//设置确定按钮
builder.setPositiveButton(positiveBtnName, positiveBtnListener);
//设置取消按钮
builder.setNegativeButton(negativeBtnName, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
//创建一个消息对话框
dialog = builder.create();
return dialog;
}
//自定义取消按钮事件
public static Dialog createConfirmDialog(Context context, String title, String message,
String positiveBtnName, String negativeBtnName, DialogInterface.OnClickListener positiveBtnListener,
DialogInterface.OnClickListener negativeBtnListener) {
Dialog dialog = null;
AlertDialog.Builder builder = new AlertDialog.Builder(context);
//设置对话框标题
builder.setTitle(title);
//设置对话框消息
builder.setMessage(message);
//设置确定按钮
builder.setPositiveButton(positiveBtnName, positiveBtnListener);
//设置取消按钮
builder.setNegativeButton(negativeBtnName, negativeBtnListener);
//创建一个消息对话框
dialog = builder.create();
return dialog;
}
//endregion
//region 单选 弹出框
public static Dialog createRadioDialog(Context context, String title, final String[] ss , DialogInterface.OnClickListener btnListener) {
Dialog dialog = null;
AlertDialog.Builder builder = new AlertDialog.Builder(context);
//设置对话框标题
builder.setTitle(title);
builder.setSingleChoiceItems(ss, 1, btnListener);
//创建一个消息对话框
dialog = builder.create();
return dialog;
}
//endregion
}
调用方式:
点击btn按钮时,弹出对话框。
确认后,执行你的方法();
调用确认框
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Dialog dialog = MyAlertDialog.createConfirmDialog(InboundPOActivity.this, "提交", "入库确认", "确定", "取消",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
你的方法();
}
});
dialog.show();
}
});
调用单选框
final String[] ss={"1","2","3"};
Dialog dialog = MyAlertDialog.createRadioDialog(InboundPOActivity.this,"Test",ss,new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
Toast.makeText(InboundPOActivity.this, "性别为:" + ss[which], Toast.LENGTH_SHORT).show();
}
});
dialog.show();
Android Dialog 简单封装的更多相关文章
- Android AsyncTask 深度理解、简单封装、任务队列分析、自定义线程池
前言:由于最近在做SDK的功能,需要设计线程池.看了很多资料不知道从何开始着手,突然发现了AsyncTask有对线程池的封装,so,就拿它开刀,本文将从AsyncTask的基本用法,到简单的封装,再到 ...
- Android ToolBar 的简单封装
使用过 ToolBar 的朋友肯定对其使用方法不陌生,由于其使用方法非常easy.假设对 ActionBar 使用比較熟练的人来说.ToolBar 就更easy了!只是,相信大家在使用的过程中都遇到过 ...
- android常用对话框封装
在android开发中,经常会用到对话框跟用户进行交互,方便用户可操作性:接下来就对常用对话框进行简单封装,避免在项目中出现冗余代码,加重后期项目的维护量:代码如有问题欢迎大家拍砖指正一起进步. 先贴 ...
- Android--Retrofit+RxJava的简单封装(三)
1,继续接着上一篇的讲讲,话说如果像上一篇这样的话,那么我们每一次请求一个结构都要创建一堆的Retrofit对象,而且代码都是相同的,我们可以试试封装一下 先创建一个HttpMethods类,将Ret ...
- Android Dialog使用举例
在Android开发中,我们经常会需要在Android界面上弹出一些对话框,比如询问用户或者让用户选择.这些功能我们叫它Android Dialog对话框,在我们使用Android的过程中,我归纳了一 ...
- Google图片加载库Glide的简单封装GlideUtils
Google图片加载库Glide的简单封装GlideUtils 因为项目里用的Glide的地方比较多,所有简单的封装了以下,其实也没什么,就是写了个工具类,但是还是要把基础说下 Glide的Githu ...
- android Glide简单使用
版权声明:大家可以转载,请写明转载申明 https://blog.csdn.net/bzlj2912009596/article/details/81702367 今天,简单讲讲Android里Gli ...
- Android控件——7种形式的Android Dialog使用举例(转载)
在Android开发中,我们经常会需要在Android界面上弹出一些对话框,比如询问用户或者让用户选择.这些功能我们叫它Android Dialog对话框,在我们使用Android的过程中,我归纳了一 ...
- React Native之Fetch简单封装、获取网络状态
1.Fetch的使用 fetch的使用非常简单,只需传入请求的url fetch('https://facebook.github.io/react-native/movies.json'); 当然是 ...
随机推荐
- Spectral Bounds for Sparse PCA: Exact and Greedy Algorithms[贪婪算法选特征]
目录 概括 Sparse PCA Formulation 非常普遍的问题 Optimality Conditions Eigenvalue Bounds 算法 代码 概括 这篇论文,不像以往的那些论文 ...
- Acceleration for ML 论文导读
Energy efficient parallel neuromorphic architectures with approximate arithmetic on FPGA Motivation ...
- C#对摄像头的操作示例,采用Aforge库
操作摄像头有三个办法:VFW.DirectShow.花钱买第三方控件 VFW技术比较古老,无法解决驱动不完善造成的某些问题 DirectShow技术相对完善一些,但这是C++才能实现的技术.如果用.N ...
- 自定义threading.local
1.threading相关. # Author:Jesi # Time : 2018/12/28 14:21 import threading import time from threading i ...
- Java Core - JVM运行时内存管理
在读正文之前,阅读以下两篇博客学习并理解堆栈.作用域.本地方法的概念. 作用域:https://www.cnblogs.com/AlanLee/p/6627949.html 操作数栈:https:// ...
- Column 'parent_id' specified twice
Hibernate Column 'parent_id' specified twice问题解决--insertable = false, updatable = false的使用 - shendeg ...
- 使用node写一个简单的页面操作
let http = require('http'); let urlStr = require('url'); let fs = require('fs'); let path = require( ...
- Day 4-11 re正则表达式
正则表达式就是字符串的匹配规则,在多数编程语言里都有相应的支持,python里对应的模块是re '.' 默认匹配除\n之外的任意一个字符,若指定flag DOTALL,则匹配任意字符,包括换行 '^' ...
- Programming好文解读系列(—)——代码整洁之道
注:初入职场,作为一个程序员,要融入项目组的编程风格,渐渐地觉得系统地研究下如何写出整洁而高效的代码还是很有必要的.与在学校时写代码的情况不同,实现某个功能是不难的,需要下功夫的地方在于如何做一些防御 ...
- hive之size函数和cast转换函数
size返回map集合中元素的个数: cast函数将一种类型的数据转换成其他格式的数据