How I can cancel preference dialog closing aftet any button clicked?
I solved to make that my dialog class implemented 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
}
}
};
}
I tried to override onDismiss method, but dialog whatever closing.
@Override
public void onDismiss(DialogInterface dialog) {
// TODO Auto-generated method stub
Log.d("MY","onDismiss");
//super.onDismiss(dialog);
}
The solution of my question is overriding of showDialog-method.
@Override
protected void showDialog(Bundle state) {
// TODO Auto-generated method stub
super.showDialog(state);
((AlertDialog) getDialog()).getButton(AlertDialog.BUTTON_POSITIVE)
.setOnClickListener(this);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With