Select all text inside EditText when it gets focus

Galip picture Galip · Jan 12, 2011 · Viewed 126.7k times · Source

I have an EditText with some dummy text in it. When the user clicks on it I want it to be selected so that when the user starts typing the dummy text gets deleted.

How can I achieve this?

Answer

TheCottonSilk picture TheCottonSilk · Jan 12, 2011

You can try in your main.xml file:

android:selectAllOnFocus="true"

Or, in Java, use

editText.setSelectAllOnFocus(true);