如何让AlertDialog 在点击确定或者取消时不消失
2014-01-15 11:26
330 查看
查看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点击 确定或者取消按钮 对话框自动消失的 解决办法
- AlertDialog点击按钮确定或取消不消失
- Android studio 的AlertDialog控件,要实现点击确定和取消按钮时,对话框消失;点击空白处,对话框
- Android开发,禁止AlertDialog点击确定或者取消都自动关闭dialog的情况
- 如何让通知不被清除或者点击后不消失?
- Android让AlertDialog点击确定不会消失
- android 如何让通知不被清除或者点击后不消失?
- Android让AlertDialog点击确定不会消失
- Android 点击AlertDialog上的确定和取消按钮,使对话框不消失
- Alertdialog对话框,设置点击其他位置不消失
- android 让通知不被清除或者点击后不消失