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
You could have your calling activity implement a custom listener interface that is called when the dialog closes:
public interface MyDialogListener {
void OnCloseDialog();
}
public class MyActivity implements MyDialogListener {
public void SomeMethod() {
MyDialog myDialog = new MyDialog(this, this);
myDialog.show();
}
public void OnCloseDialog() {
// Do whatever you want to do on close here
}
}
public class MyDialog extends Dialog {
MyDialogListener mListener;
public MyDialog (Context context, MyDialogListener listener) {
super(context, R.style.Dialog);
mListener = listener;
}
public void onClick(View view) {
switch (view.getId()) {
case R.id.CloseButton:
mListener.OnCloseDialog();
dismiss()
break;
default:
//...
}
}
}
This is especially useful if you want to send stuff back to the caller at any other time besides on dismissal.