Source:
public Dialog onCreateDialog(Bundle savedInstanceState) { final Context context = getContext(); final LayoutInflater inflater = LayoutInflater.from(context); final View customTitle = inflater.inflate(R.layout.network_request_dialog_title, null); final TextView title = customTitle.findViewById(R.id.network_request_title_text); title.setText(getTitle()); final Intent intent = getActivity().getIntent(); if (intent != null) { mIsSpecifiedSsid = intent.getBooleanExtra(EXTRA_IS_SPECIFIED_SSID, false); } final ProgressBar progressBar = customTitle.findViewById( R.id.network_request_title_progress); progressBar.setVisibility(View.VISIBLE); mDialogAdapter = new AccessPointAdapter(context, R.layout.preference_access_point, getAccessPointList()); final AlertDialog.Builder builder = new AlertDialog.Builder(context) .setCustomTitle(customTitle) .setAdapter(mDialogAdapter, this) .setNegativeButton(R.string.cancel, (dialog, which) -> onCancel(dialog)) .setNeutralButton(R.string.network_connection_request_dialog_showall, null ); if (mIsSpecifiedSsid) { builder.setPositiveButton(R.string.wifi_connect, null ); } final AlertDialog dialog = builder.create(); dialog.getListView() .setOnItemClickListener( (parent, view, position, id) -> this.onClick(dialog, position)); setCancelable(false); dialog.setOnShowListener((dialogInterface) -> { final Button neutralBtn = dialog.getButton(AlertDialog.BUTTON_NEUTRAL); neutralBtn.setVisibility(View.GONE); neutralBtn.setOnClickListener(v -> { mShowLimitedItem = false; renewAccessPointList(null ); notifyAdapterRefresh(); neutralBtn.setVisibility(View.GONE); }); if (mIsSpecifiedSsid) { final Button positiveBtn = dialog.getButton(AlertDialog.BUTTON_POSITIVE); positiveBtn.setOnClickListener(v -> { this.onClick(dialog, 0 ); }); positiveBtn.setEnabled(false); } }); return dialog; }

Target:
public Dialog onCreateDialog(Bundle savedInstanceState) { final Context context = getContext(); final LayoutInflater inflater = LayoutInflater.from(context); final View customTitle = inflater.inflate(R.layout.network_request_dialog_title, null); final TextView title = customTitle.findViewById(R.id.network_request_title_text); title.setText(getTitle()); final Intent intent = getActivity().getIntent(); if (intent != null) { mIsSpecifiedSsid = intent.getBooleanExtra(EXTRA_IS_SPECIFIED_SSID, false); } mDialogAdapter = new AccessPointAdapter(context, R.layout.preference_access_point, getAccessPointList()); final AlertDialog.Builder builder = new AlertDialog.Builder(context) .setCustomTitle(customTitle) .setAdapter(mDialogAdapter, this) .setNegativeButton(R.string.cancel, (dialog, which) -> onCancel(dialog)) .setNeutralButton(R.string.network_connection_request_dialog_showall, null ); if (mIsSpecifiedSsid) { builder.setPositiveButton(R.string.wifi_connect, null ); } final AlertDialog dialog = builder.create(); dialog.getListView() .setOnItemClickListener( (parent, view, position, id) -> this.onClick(dialog, position)); setCancelable(false); dialog.setOnShowListener((dialogInterface) -> { final Button neutralBtn = dialog.getButton(AlertDialog.BUTTON_NEUTRAL); neutralBtn.setVisibility(View.GONE); neutralBtn.setOnClickListener(v -> { mShowLimitedItem = false; renewAccessPointList(null ); notifyAdapterRefresh(); neutralBtn.setVisibility(View.GONE); }); if (mIsSpecifiedSsid) { final Button positiveBtn = dialog.getButton(AlertDialog.BUTTON_POSITIVE); positiveBtn.setOnClickListener(v -> { this.onClick(dialog, 0 ); }); positiveBtn.setEnabled(false); } }); return dialog; }