Search code examples
androidandroid-edittext

Select all text inside EditText when it gets focus


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?


Solution

  • You can try in your main.xml file:

    android:selectAllOnFocus="true"
    

    Or, in Java, use

    editText.setSelectAllOnFocus(true);