我该如何在点击任何按钮后取消首选项对话框的关闭?
我解决了这个问题,使我的对话框类实现了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);
}