Reputation: 658
I'm writing a very simple dialog fragment that displays 3 choices and returns the choice back to a parent fragment. After a choice is made I want the dialog to dismiss itself. Below is the onCreateDialogMethod I wrote, with a call to CheckOutDialogFragment.this.dismiss(). I've also tried just dismiss() and a couple other methods. Any advice?
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
activity = this.getActivity();
Bundle args = getArguments();
final String comment = args.getString(CheckInOutFragment.COMMENT);
AlertDialog.Builder myAlertDialog = new AlertDialog.Builder(activity);
dialogAdapter = new CheckOutDialogAdapter(this.getActivity());
final Intent data = new Intent();
myAlertDialog.setSingleChoiceItems(dialogAdapter, -1, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int selection){
ActivityModel.CheckOutType type = dialogAdapter.getActivityTypeForIndex(selection);
data.putExtra(CheckInOutFragment.COMMENT, comment);
data.putExtra(CHOICE, type);
getTargetFragment().onActivityResult(getTargetRequestCode(), Activity.RESULT_OK, data);
CheckOutDialogFragment.this.dismiss();
//TODO: figure out why this won't dismiss
}
});
return myAlertDialog.create();
}
Upvotes: 1
Views: 482
Reputation: 658
Turns out that my IDE needed a restart and my project wasn't building properly. Both CheckOutDialogFragment.this.dismiss() and dismiss() work.
Upvotes: 2
Reputation: 75629
Instead of:
CheckOutDialogFragment.this.dismiss();
is should be just:
dismiss();
Upvotes: 2