如何让AlertDialog 在点击确定或者取消时不消失
来源:互联网 发布:小米旗舰店淘宝 编辑:程序博客网 时间:2024/05/19 13:08
查看AlertDialog的源代码,如下:
/**
* Set a listener to be invoked when the positive button of the dialog is pressed.
* @param textId The resource id of the text to display in the positive button
* @param listener The {@link DialogInterface.OnClickListener} to use.
*
* @return This Builder object to allow for chaining of calls to set methods
*/
public Builder setPositiveButton(int textId, final OnClickListener listener) {
P.mPositiveButtonText = P.mContext.getText(textId);
P.mPositiveButtonListener = listener;
return this;
}
public Builder setPositiveButton(CharSequence text, final OnClickListener listener) {
P.mPositiveButtonText = text;
P.mPositiveButtonListener = listener;
return this;
}
public Builder setNegativeButton(int textId, final OnClickListener listener) {
P.mNegativeButtonText = P.mContext.getText(textId);
P.mNegativeButtonListener = listener;
return this;
}
public Builder setNegativeButton(CharSequence text, final OnClickListener listener) {
P.mNegativeButtonText = text;
P.mNegativeButtonListener = listener;
return this;
}
注意看注释第一句:Set a listener to be invoked when the positive button of the dialog is pressed,这个Listener是监听button被点击事件。我们的目的是让AlertDialog 在点击确定或者取消时不消失,那么屏蔽此Listener即可。
解决方法:
继承AlertDialog自定义自己的AlertDialog,重写以上四个方法:(把这四个方法拷贝过来,都不要这两句:
P.mPositiveButtonListener = listener;
P.mNegativeButtonListener = listener;)
此外还有不常用的这个按钮,如法炮制。
public Builder setNeutralButton(int textId, final OnClickListener listener)
public Builder setNeutralButton(CharSequence text, final OnClickListener listener)
其他不同的解决方法:http://blog.csdn.net/abby_dcy/article/details/6049535
- 如何让AlertDialog 在点击确定或者取消时不消失
- 如何让AlertDialog 在点击确定或者取消时不消失
- 【转】如何让AlertDialog 在点击确定或者取消时不消失
- 如何让AlertDialog 在点击确定或者取消时不消失
- 如何让AlertDialog 在点击确定或者取消时不消失
- 如何让AlertDialog 在点击确定或者取消时不消失
- 如何让AlertDialog 在点击确定或者取消时不消失
- 如何让AlertDialog 在点击确定或者取消时不消失
- AlertDialog点击按钮确定或取消不消失
- Android下关于AlertDialog点击 确定或者取消按钮 对话框自动消失的 解决办法
- Android让AlertDialog点击确定不会消失
- Android让AlertDialog点击确定不会消失
- 让AlertDialog在点击按钮后不消失、不关闭
- 让AlertDialog在点击按钮后不消失、不关闭
- 让AlertDialog在按钮被点击后不消失
- 让AlertDialog在按钮被点击后不消失
- 让AlertDialog在按钮被点击后不消失
- 让AlertDialog在按钮被点击后不消失
- Android Touch事件 两点旋转实现思路
- hdu 1576 A/B
- jquery实现checkbox选中功能
- Robots.txt实战教程
- Iscroll4使用心得
- 如何让AlertDialog 在点击确定或者取消时不消失
- poj 1579 Function Run Fun
- jQuery插件的写法
- 取List<Object>的值
- Oracle报ORA-01722错误的排查经验
- linux IptabLex 攻击
- 深入分析 Java 中的中文编码问题
- cocos2d-x动作、特效和动画(三)旋转和跳跃动作
- 爆流的随便画教程—NO12 画嘞个剑