简体   繁体   中英

how to change visibility edittext in mainactivity from alertdialog

I have designed an alertdialog of which when the user press the save button

MainActivity

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

and I have editText in MainActivity ,I want to change visibility for editText when press onClick in .setPositiveButton

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

In the same way you can call getActivity().getLayoutInflater() , you can call getActivity().findViewById() :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM