HOW TO HIDE AND SHOW EDITTEXT?

Hugh Jackman

Total Post:52

Points:366
Posted by  Hugh Jackman
 1045  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. Kamlakar Singh

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

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!