My DialogFragment class is invoked when I press a button on a activity. I want the date set through this DialogFragment to be displayed on the buttons text. FindViewById re
here's a good pattern to follow:
something like,
class MyDialogFragment extends DialogFragment implements DialogInterface.OnClickListener {
static interface Listener {
void onOkay(MyObject result);
void onCancel();
}
...
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
...
// set this as a listener for ok / cancel buttons
return new AlertDialog.Builder(activity)...whatever...
.setPositiveButton(R.string.ok, this)
.setNegativeButton(R.string.cancel, this).create();
}
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == DialogInterface.BUTTON_POSITIVE) {
if (getActivity() instanceof Listener) {
((Listener)getActivity()).onOkay(...);
}
} else {
if (getActivity() instanceof Listener) {
((Listener)getActivity()).onCancel();
}
}
}
}
class MyActivity extends Activity implements MyDialogFragment.Listener {
...
@Override
public void onOkay(MyObject result) {
// update activity view here with result
}
@Override
public void onCancel() {
// anything?
}
}
if your case, the "result" passed into the onOkay() method would be the Date object picked by the user in the dialog.