How do I get the choice selected from AlertDialogFragment in the Activity that called it?

I'm trying to follow androids documentation on how to create an AlertDialog Fragment from here. https://developer.android.com/reference/android/app/DialogFragment.html specifically this portion of the code :

public static class MyAlertDialogFragment extends DialogFragment {  public static MyAlertDialogFragment newInstance(int title) {     MyAlertDialogFragment frag = new MyAlertDialogFragment();     Bundle args = new Bundle();     args.putInt("title", title);     frag.setArguments(args);     return frag; }  @Override public Dialog onCreateDialog(Bundle savedInstanceState) {     int title = getArguments().getInt("title");      return new AlertDialog.Builder(getActivity())             .setIcon(R.drawable.alert_dialog_icon)             .setTitle(title)             .setPositiveButton(R.string.alert_dialog_ok,                 new DialogInterface.OnClickListener() {                     public void onClick(DialogInterface dialog, int whichButton) {                         ((FragmentAlertDialog)getActivity()).doPositiveClick();                     }                 }             )             .setNegativeButton(R.string.alert_dialog_cancel,                 new DialogInterface.OnClickListener() {                     public void onClick(DialogInterface dialog, int whichButton) {                         ((FragmentAlertDialog)getActivity()).doNegativeClick();                     }                 }             )             .create(); } 

}

and it says: "The activity creating this fragment may have the following methods to show the dialog and receive results from it:"

public void showDialog() { DialogFragment newFragment = MyAlertDialogFragment.newInstance(         R.string.alert_dialog_two_buttons_title); newFragment.show(getFragmentManager(), "dialog"); }  public void doPositiveClick() {     // Do stuff here.     Log.i("FragmentAlertDialog", "Positive click!"); }  public void doNegativeClick() {     // Do stuff here.  Log.i("FragmentAlertDialog", "Negative click!"); } 

but I'm also adding the option of setSingleChoiceitems from my array with this code snippet before .setPositiveButton:

                .setSingleChoiceItems(R.array.status_selection, 3, new    DialogInterface.OnClickListener(){                 public void onClick(DialogInterface dialog, int id){                     //do nothing                 }             }) 

My question is how do I retrieve what was selected from the singliechoiceitem in the activity that I used to call this alertDialogFragment?

Thanks in advance!

Replay

Category: android alertdialog Time: 2016-07-29 Views: 0

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 0.194 (s). 12 q(s)