Source:
public Dialog onCreateDialog(Bundle savedInstanceState) { View view = View.inflate(getActivity(), R.layout.dialog_overwrite_project, null); inputLayout = view.findViewById(R.id.input); inputLayout.getEditText().setText(programName); radioGroup = view.findViewById(R.id.radio_group); radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) { switch (checkedId) { case R.id.replace: inputLayout.setVisibility(TextView.GONE); break; case R.id.rename: inputLayout.setVisibility(TextView.VISIBLE); break; } } }); radioGroup.check(R.id.rename); final AlertDialog alertDialog = new AlertDialog.Builder(getActivity()) .setView(view) .setTitle(R.string.overwrite_title) .setMessage(R.string.overwrite_text) .setPositiveButton(R.string.ok, null) .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { ToastUtil.showError(getActivity(), R.string.notification_download_project_cancel); DownloadUtil.getInstance().downloadCanceled(url); } }) .create(); alertDialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { Button buttonPositive = alertDialog.getButton(DialogInterface.BUTTON_POSITIVE); buttonPositive.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (handlePositiveButtonClick()) { dismiss(); } } }); buttonPositive.setEnabled(!inputLayout.getEditText().getText().toString().isEmpty()); DialogInputWatcher inputWatcher = new DialogInputWatcher(inputLayout, buttonPositive, false); inputLayout.getEditText().addTextChangedListener(inputWatcher); } }); inputLayout.getEditText().setOnFocusChangeListener(new OpenSoftkeyboardRightAway(alertDialog)); return alertDialog; }

Target:
public Dialog onCreateDialog(Bundle savedInstanceState) { View view = View.inflate(getActivity(), R.layout.dialog_overwrite_project, null); inputLayout = view.findViewById(R.id.input); inputLayout.getEditText().setText(programName); radioGroup = view.findViewById(R.id.radio_group); radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) { switch (checkedId) { case R.id.replace: inputLayout.setVisibility(TextView.GONE); break; case R.id.rename: inputLayout.setVisibility(TextView.VISIBLE); break; } } }); final AlertDialog alertDialog = new AlertDialog.Builder(getActivity()) .setView(view) .setTitle(R.string.overwrite_title) .setPositiveButton(R.string.ok, null) .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { ToastUtil.showError(getActivity(), R.string.notification_download_project_cancel); DownloadUtil.getInstance().downloadCanceled(url); } }) .create(); alertDialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { Button buttonPositive = alertDialog.getButton(DialogInterface.BUTTON_POSITIVE); buttonPositive.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (handlePositiveButtonClick()) { dismiss(); } } }); buttonPositive.setEnabled(!inputLayout.getEditText().getText().toString().isEmpty()); DialogInputWatcher inputWatcher = new DialogInputWatcher(inputLayout, buttonPositive, false); inputLayout.getEditText().addTextChangedListener(inputWatcher); } }); inputLayout.getEditText().setOnFocusChangeListener(new OpenSoftkeyboardRightAway(alertDialog)); return alertDialog; }