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 系统中,一段时间不操作键盘和鼠标,屏幕便会关闭,系统会进入睡眠状态.但有些程序(比如游戏.视频和演示文稿)在运行过程中应该 ...
随机推荐
- (2/24) 快速上手一个webpack的demo
写在前面:该部分的安装都是基于windows系统的,且此处的webpack的版本为:3.6.0. 1.安装webpack 1.1 安装方法: 用win+R打开运行对话框,输入cmd进入命令行模式.然后 ...
- 725. Split Linked List in Parts
▶ 将一个单链表拆分为长度尽量接近的 k 段 ● 自己的代码,12 ms ■ 记链表长度为 count,目标段数为 k,quo = count / k,mod = count % k,part = m ...
- Angular2中Input和Output
@Input @Input是用来定义模块的输入的,用来让父模块往子模块传递内容: @Output 子模块自定义一些event传递给父模块用@Output. 对于angular2中的Input和Outp ...
- sudo免密码
很多都是修改/etc/sudoers权限为740再加上一句 ALL=NOPASSWD:ALL 或者加一句 yourname ALL=(ALL) NOPASSWD: ALL 然后权限改回440 先说第一 ...
- Linux 入侵检测
一.检查系统日志 检查系统错误登陆日志,统计IP重试次数 # 这里使用了lastb命令,该命令需要root权限,可以显示所有登陆信息.这里仅仅显示的root用户的,读者可以更具实际情况自行确定,或者直 ...
- linux之cut
[linux之cut] -b:字节 -c:字符 -d:自定义域 -f:域范围 参考:http://wenku.baidu.com/view/9399bc8383d049649b66588b.html
- python操作vmware
import pysphere from pysphere import VIServer host_ip = "200.200.173.45" username = " ...
- Golang基本结构之练习(day2)
笔记: . 任何一个代码文件隶属于一个包 . import 关键字,引用其他包: import(“fmt”) import(“os”) 通常习惯写成: import ( “fmt” “os” ) . ...
- 在Linux下访问Windows共享文件夹
说明 以下操作以Ubuntu为例,大家可以参考. 我在Ubuntu 14.04和16.04都试过了. Windows共享文件夹 如果局域网内有一台Windows主机,将指定文件夹设为共享,就可以在局域 ...
- strops()
<?php echo strpos("You love php, I love php too!","php"); ?>