1.AlertDialog点击时不自动消失

//在setPositiveButton和setNegativeButton根据自己的逻辑处理,大概代码如下
if(validate){//验证通过自动消失
setDialogDismissable(dialog, true);
}else{//验证没通过,不能消失
setDialogDismissable(dialog, false)
} void setDialogDismissable(DialogInterface dialog, boolean dismissable){
try {
Field field = dialog.getClass().getSuperclass().getDeclaredField("mShowing");
field.setAccessible(true);
field.set(dialog, dismissable);
} catch (Exception e) {
e.printStackTrace();
}
}

2.AlertDialog显示(EditText)时,自动弹出软键盘代码如下

final EditText textEdit = new EditText(this);

// Builder
AlertDialog.Builder builder = new AlertDialog.Builder(this);
//TODO:builder.setTitle(""); // Dialog
AlertDialog dialog = builder.create();
dialog.setOnShowListener(new OnShowListener() { @Override
public void onShow(DialogInterface dialog) {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(textEdit, InputMethodManager.SHOW_IMPLICIT);
}
}); dialog.show();

注意:上面代码是dialog.show(), 不是builder.show();

AlertDialog的更多相关文章

  1. Stack Overflow 排错翻译 - Closing AlertDialog.Builder in Android -Android环境中关闭AlertDialog.Builder

    Stack Overflow 排错翻译  - Closing AlertDialog.Builder in Android -Android环境中关闭AlertDialog.Builder 转自:ht ...

  2. Android中的AlertDialog使用示例五(自定义对话框)

    在Android开发中,我们经常会需要在Android界面上弹出一些对话框,比如询问用户或者让用户选择.这些功能我们叫它Android Dialog对话框,AlertDialog实现方法为建造者模式. ...

  3. android 弹出AlertDialog的学习案例

    我在编写的时候,测试的关键代码: AlertDialog.Builder builder=new AlertDialog.Builder(MainPointListActivity.this); bu ...

  4. The method setPositiveButton(int, DialogInterface.OnClickListener) in the type AlertDialog.Builder is not applicable for the arguments

    The method setPositiveButton(int, DialogInterface.OnClickListener) in the type AlertDialog.Builder i ...

  5. setView的AlertDialog在受到二次点击后出错

    错误报告: 10-21 13:11:16.009: E/AndroidRuntime(27937): FATAL EXCEPTION: main10-21 13:11:16.009: E/Androi ...

  6. 关于AlertDialog.Builder(Context context)中所应传入的context

    错误报告: 10-20 14:34:46.565: E/AndroidRuntime(23098): FATAL EXCEPTION: main10-20 14:34:46.565: E/Androi ...

  7. 安卓 自定义AlertDialog对话框(加载提示框)

    AlertDialog有以下六种使用方法: 一.简单的AlertDialog(只显示一段简单的信息) 二.带按钮的AlertDialog(显示提示信息,让用户操作) 三.类似ListView的Aler ...

  8. Android AlertDialog去除黑边白边自定义布局(转)

    LayoutInflater inflater = this.getLayoutInflater(); View view = inflater.inflate(R.layout.test_alert ...

  9. Android开发2:事件处理及实现简单的对话框(Toast,AlertDialog,Snackbar,TextInputLayout的使用)

    前言 啦啦啦~又要和大家一起学习Android开发啦,博主心里好激动哒~ 在上篇博文中,我们通过线性布局和基础组件的使用,完成了一个简单的学生课外体育积分电子认证系统的界面,本篇博文,将和大家一起熟悉 ...

  10. Android中的AlertDialog使用示例四(多项选择确定对话框)

    在Android开发中,我们经常会需要在Android界面上弹出一些对话框,比如询问用户或者让用户选择.这些功能我们叫它Android Dialog对话框,AlertDialog实现方法为建造者模式. ...

随机推荐

  1. HDU1353+贪心

    注意精度. /* */ #include<stdio.h> #include<string.h> #include<stdlib.h> #include<al ...

  2. 【转】深入研究java.lang.Runtime类

    一.概述      Runtime类封装了运行时的环境.每个 Java 应用程序都有一个 Runtime 类实例,使应用程序能够与其运行的环境相连接.      一般不能实例化一个Runtime对象, ...

  3. GridBagLayout:网格包布局管理器

    GridBagLayout:网格包布局管理器   GridBagLayout可以说是布局管理器Layout中最复杂的一个,其中涉及到的参数也比较得多,比如说: GridBagConstraints g ...

  4. *IntelliJ IDEA使用Hibernate连接数据库

    在IntelliJ IDEA中配置MySQL Database.

  5. 功能齐全、效率一流的免费开源数据库导入导出工具(c#开发,支持SQL server、SQLite、ACCESS三种数据库),每月借此处理数据5G以上

    软件名:DataPie 功能:支持SQL server.SQLite.ACCESS数据库的导入.导出.存储过程调用,支持EXCEL2007.EXCEL2003.ACCESS2007. CSV文件导入数 ...

  6. Eclipse搭建Struts框架,及一个简单的Struts例子

    一.下载struts2.0.1 http://struts.apache.org/downloads.html,下载struts-2.0.1-all.zip,这个压缩包中包含了开发struts2所需的 ...

  7. bzoj1061: [Noi2008]志愿者招募

    线性规划与费用流.http://www.cnblogs.com/iiyiyi/p/5616080.html.数组范围开错了!!!然后2.31-1=0x7fffffff!=0x7f7f7f7f. 开始以 ...

  8. (三)学习MVC之密码加密及用户登录

    1.密码加密采用SHA256 算法,此类的唯一实现是 SHA256Managed.在Common/Text.cs里添加Sha256方法: public static string Sha256(str ...

  9. Oracle函数:求两个数的最小公倍数

    CREATE or replace function GetGbs(num1 NUMBER,num2 NUMBER) RETURN NUMBER is resultnum NUMBER; maxnum ...

  10. Selenium2Library系列 keywords 之 _SelectElementKeywords 之 get_list_items(self, locator)

    def get_list_items(self, locator): """Returns the values in the select list identifie ...