0

From Google Developer UI guide You can accomplish a wide variety of dialog designs—including custom layouts and those described in the Dialogs design guide—by extending DialogFragment and creating a AlertDialog in the onCreateDialog() callback method.

For example, here's a basic AlertDialog that's managed within a DialogFragment:

What?

    public class ResetAll    extends DialogFragment {
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {          
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setMessage(R.string.reset)
                .setPositiveButton(R.string.reset2, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        // code
                    }
                })
                .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        // code
                    }
                });           
        return builder.create();
    }
}

Use here the Class?

 @Override
   public boolean onOptionsItemSelected(MenuItem item) {        
    int id = item.getItemId();
    if (id == R.id.action_settings) {

       // USE HERE! DIALOG

    }
    return super.onOptionsItemSelected(item);
}
Khaled Lela
  • 7,831
  • 6
  • 45
  • 73
Dan Even
  • 5
  • 4

1 Answers1

0
@Override
   public boolean onOptionsItemSelected(MenuItem item) {        
    int id = item.getItemId();
    if (id == R.id.action_settings) {

       // USE HERE! DIALOG
       ResetAll dialog = new ResetAll();
       dialog.show(getSupportFragmentManager(), "restFragmentDialog");

// restFragmentDialog is a unique tag name that the system uses to save and restore the fragment state when necessary.
// The tag also allows you to get a handle to the fragment by calling findFragmentByTag().

    }
    return super.onOptionsItemSelected(item);
}

From Google UI link mentioned on question.

Showing a Dialog

When you want to show your dialog, create an instance of your DialogFragment and call show(), passing the FragmentManager and a tag name for the dialog fragment.

You can get the FragmentManager by calling getSupportFragmentManager() from the FragmentActivity or getFragmentManager() from a Fragment.

Khaled Lela
  • 7,831
  • 6
  • 45
  • 73