Select all text inside EditText when it gets focus


Question

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?

1
219
1/12/2011 1:47:06 PM

Accepted Answer

You can try in your main.xml file:

android:selectAllOnFocus="true"
489
3/18/2013 9:47:30 AM

editText.setSelectAllOnFocus(true);

This works if you want to do it programatically.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon