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);
}