如何在单击任何按钮后取消首选项对话框关闭?
我解决了让我的对话框类实现 OnClickListener 的问题。
public class PassChangeDiglog extends DialogPreference implements
OnClickListener {
EditText oldpass, new_pass1, new_pass2;
public PassChangeDiglog(Context context, AttributeSet attrs) {
super(context, attrs);
setDialogLayoutResource(R.layout.pass_change_diglog);
setPositiveButtonText("OK");
setNegativeButtonText(R.string.Cancel);
}
@Override
protected void onBindDialogView(View view) {
setTitle(R.string.PassChanging);
oldpass = (EditText) view.findViewById(R.id.Dlg_old_pass);
new_pass1 = (EditText) view.findViewById(R.id.Dlg_NewPass1);
new_pass2 = (EditText) view.findViewById(R.id.Dlg_NewPass2);
super.onBindDialogView(view);
}
@Override
public void onClick(DialogInterface arg0, int arg1) {
switch (arg1) {
case DialogInterface.BUTTON_POSITIVE:
boolean needclose;
...
if (needclose)
arg0.dismiss();
else{
//do not close
}
}
};
}
我试图重写 onDismiss 方法,但不管关闭什么对话框。
@Override
public void onDismiss(DialogInterface dialog) {
// TODO Auto-generated method stub
Log.d("MY","onDismiss");
//super.onDismiss(dialog);
}
最佳答案
我的问题的解决方案是覆盖 showDialog 方法。
@Override
protected void showDialog(Bundle state) {
// TODO Auto-generated method stub
super.showDialog(state);
((AlertDialog) getDialog()).getButton(AlertDialog.BUTTON_POSITIVE)
.setOnClickListener(this);
}
关于android - 单击肯定按钮后如何取消首选项对话框关闭?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21536921/