Java – How do I automatically clear text in EditText?

How do I automatically clear text in EditText?… here is a solution to the problem.

How do I automatically clear text in EditText?

final TextView textView = (TextView) findViewById(;

final EditText editText = (EditText) findViewById(;

Button button = (Button) findViewById(;
button.setOnClickListener(new View.OnClickListener() {

    public void onClick(View v) {
        String etString = editText.getText().toString();

I’m new to coding and I don’t know how to automatically clear text in EditText so users don’t have to do it themselves. You can see in all “big” websites when you enter text in a text box (for example: “What’s your name?”) ), you will see “Name” in the text box, and when you click on it, it disappears. How do I make text disappear automatically without users manually deleting it?


You’re not actually referring to the text you’re setting — it’s a hint (that’s why it doesn’t show up after EditText gets focus or text has already been entered). You can set these placeholder hints in the EditText XML, for example:

android:hint="First Name". 

If you’re really adventurous, < a href="" rel="noreferrer noopener nofollow" > you can also wrap your EditText in a TextInputLayout for a Material Design style floating hint.

Be sure to accept this answer if it helps.

Related Problems and Solutions