Android阻止AlertDialog关闭
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle("测试"); LayoutInflater inflater = getActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.dialogfragment_num_input, null);
builder.setView(view); builder.setPositiveButton("确定",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) { Field field = null; try {
//通过反射获取dialog中的私有属性mShowing
field = dialog.getClass().getSuperclass().getDeclaredField("mShowing");
field.setAccessible(true);//设置该属性可以访问
} catch (Exception ex) { } String inputValue = String.valueOf(mEdit.getText());
if (inputValue == null || "".equals(inputValue)) {
try {
//设置dialog不可关闭
field.set(dialog, false);
dialog.dismiss();
} catch (Exception ex) {
}
} else { //
//做自己的事
//
try {
//关闭
field.set(dialog, true);
dialog.dismiss();
} catch (Exception ex) {
}
}
}
});
builder.setNegativeButton("取消",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) { Field field = null; try {
//通过反射获取dialog中的私有属性mShowing
field = dialog.getClass().getSuperclass().getDeclaredField("mShowing");
field.setAccessible(true);//设置该属性可以访问
} catch (Exception ex) {
} try {
field.set(dialog, true);
dialog.dismiss();
} catch (Exception ex) {
} }
}); builder.create();
Android阻止AlertDialog关闭的更多相关文章
- AlertDialog通过反射机制阻止Dialog关闭
在开发Android应用程序时,我们可能会用到需要用户输入的Dialog,如登录对话框等.这时候,如果用户没有输入登录信息而点击<确定>按钮时,我们并不希望登录Dialog消失,而是采用一 ...
- Stack Overflow 排错翻译 - Closing AlertDialog.Builder in Android -Android环境中关闭AlertDialog.Builder
Stack Overflow 排错翻译 - Closing AlertDialog.Builder in Android -Android环境中关闭AlertDialog.Builder 转自:ht ...
- [转]好文章:Android的AlertDialog详解
refer:http://www.2cto.com/kf/201205/131876.html AlertDialog的构造方法全部是Protected的,所以不能直接通过new一个AlertDial ...
- Android 自定义AlertDialog退出对话框
Android 自定义AlertDialog退出对话框 转 https://blog.csdn.net/wkh11/article/details/53081634在项目中很多时候会出现点击返回键出现 ...
- Android退出时关闭所有Activity的方法
Android退出时,有的Activity可能没有被关闭.为了在Android退出时关闭所有的Activity,设计了以下的类: //关闭Activity的类 public class CloseAc ...
- Android之AlertDialog.Builder详解
import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; ...
- 【Android】Android在AlertDialog使用大全
package com.ceac.deng; import android.R.string; import android.support.v7.app.ActionBarActivity; imp ...
- 【Android】Android中AlertDialog对话框的使用实例
package com.ceac.deng; import android.R.string; import android.support.v7.app.ActionBarActivity; imp ...
- .NET/C# 阻止屏幕关闭,阻止系统进入睡眠状态
原文:.NET/C# 阻止屏幕关闭,阻止系统进入睡眠状态 在 Windows 系统中,一段时间不操作键盘和鼠标,屏幕便会关闭,系统会进入睡眠状态.但有些程序(比如游戏.视频和演示文稿)在运行过程中应该 ...
随机推荐
- 分享一个jquery插件,弥补一下hover事件的小小不足
hover事件有一个缺点:当你的鼠标无意划过一个dom元素(瞬间划过,这个时候用户可能不想触发hover事件),会触发hover事件 应该设置一个时差来控制hover事件的触发 比如jd左边的菜单 你 ...
- 基于Windows 配置 nginx 集群 & 反向代理
1.下载 nginx 下载页面 : http://nginx.org/en/download.html 具体文件: http://nginx.org/download/nginx-1.7.0.zip ...
- AnyConnect removes "Connections" tab from IE Settings solution
I have an ASA 5510 that we use for SSL VPN Client access. The ASA distributes the AnyConnect (v2.4. ...
- warning LNK4099: PDB 'vc100.pdb' was not found... 解决方案
使用VS2010在编译得代码工程的时候,原本在debug下是没有问题,但是在release下编译始终会报: “warning LNK4099: PDB 'vc100.pdb' was not foun ...
- tomcat 域名直接访问默认工程,而不添加项目路径
<Engine name="Catalina" defaultHost="xx.xx.xx.xx"> <!--For clustering, ...
- iscroll源码学习(1)
iscroll是移端端开发的两大利器之一(另一个是fastclick),为了将它整合的avalon,需要对它认真学习一番.下面是我的笔记. 第一天看的是它的工具类util.js //用于做函数节流 v ...
- So you've been rejected, now what? On appeals in peer-reviewed publications(From Wiley Exchanges)
Getting rejected stinks. Wouldn’t it be great if we could appeal people’s decisions in life? Imagine ...
- 创建和运行Java项目
---------siwuxie095 首先在左侧的工程管理面板 Package Explorer 中,右键->New->Java Project ...
- Common issue on financial information exchange (FIX) Connectivity[z]
FIX Protocol Session Connectivity Hi guys, in this post I would like share my experience with financ ...
- MVC三者关系