How can I automatically clear the text in EditText?

final TextView textView = (TextView) findViewById(R.id.textView);

final EditText editText = (EditText) findViewById(R.id.editText);

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

    @Override
    public void onClick(View v) {
        String etString = editText.getText().toString();
        textView.setText(etString);
    }
});

I am new to coding and I don’t know how to automatically clear the text in an EditText so the user doesn’t have to do it themselves. You can see in all “big” websites that when you enter text into a text box (for example: “What’s your name?”) you see “first name” in the text box and when you click on it, it disappears. How can I make the text disappear automatically without the user having to delete it manually?

What you’re referring to isn’t actually text that’s being set — it’s a hint (which is why it doesn’t show after the EditText is focused or text has already been entered). You can set these placeholder hints in your EditText XML, for example:

android:hint="First Name". 

If you’re feeling really adventerous, you can also wrap your EditText in a TextInputLayout for a Material Design style floating hint.

If that helps, be sure to accept this answer.

You can do it grammatically by modifying your code to use the hint property:

editText.setText("");
editText.setHint(<string>);

also you can change color by adding

editText.setHintTextColor(<some color>);