如何从 alertdialog 更改 mainactivity 中的可见性 edittext

how to change visibility edittext in mainactivity from alertdialog

我设计了一个当用户按下保存按钮时的警告对话框

MainActivity

public void openDialog(View view) {
    RegDialog regDialog = new RegDialog();
    regDialog.show(getSupportFragmentManager(), "Register Dialog");
}

并且我在 MainActivity 中有 editText,我想在 .setPositiveButton

中按 onClick 时更改 editText 的可见性

AlertDialog

public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    LayoutInflater inflater = getActivity().getLayoutInflater();
    View view = inflater.inflate(R.layout.layout_reg_dialog, null);

    builder.setView(view)
            .setTitle("Titel")
            .setPositiveButton("Activer", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    //change visiblity editText
                }
            });

以同样的方式调用getActivity().getLayoutInflater(),你可以调用getActivity().findViewById():

@Override
public void onClick(DialogInterface dialog, int which) {
    EditText et = getActivity().findViewById(R.id.your_id_here);
    et.setVisibility(View.GONE);
}