I\'m working on a little program, and I need to add a custom dialog that passes some info to the calling acitivity when it closes. I extended the dialog class, and when I try to
And if you want to have some sort of saving inside the dialog, again, you have to use onDicmissListener
since for custom dialogs onDismiss
is not called by default:
public class CustomDialog extends Dialog implements DialogInterface.OnDismissListener {
public CustomDialog(Context context) {
super(context);
setupLayout(context);
}
public CustomDialog(Context context, int theme) {
super(context, theme);
setupLayout(context);
}
protected CustomDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
super(context, cancelable, cancelListener);
setupLayout(context);
}
private void setupLayout(Context context) {
this.context = context;
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.custom_dialog);
WindowManager.LayoutParams params = getWindow().getAttributes();
params.width = WindowManager.LayoutParams.FILL_PARENT;
getWindow().setAttributes(params);
setOnDismissListener(this);
loadPreferences();
}
private void loadPreferences() {
// ...
}
private void savePreferences() {
// ...
}
@Override
public void onDismiss(DialogInterface dialogInterface) {
savePreferences();
}
}