How to hide and show editText?

Total Post:51

Points:359
 1433  View(s)
Ratings:
Rate this:
I have an editText(hidden by default) and a button. I want to show the editText on click of the button and hide when the button again is pressed. Also the editText should hide if the editText box loses focus. How can this be done? Thank you for the help in advanced.
  1. Post:194

    Points:1396
    Re: How to hide and show editText?

    You can use like this And the main concept here is editText.setVisibility(View.GONE).


    Button button = (Button) findViewById(R.id.button);
            final EditText editText = (EditText) findViewById(R.id.edittext);
            button.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    if(editText.getVisibility()==View.VISIBLE){
                        editText.setVisibility(View.GONE);
                    } else {
                        editText.setVisibility(View.VISIBLE);
                    }
                }
            });

      Modified On Apr-06-2018 12:17:34 AM

Answer