Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android EditText: select all text while touch and clear when user starts typing.

I have a edit text in my app. When the user touches the edit text the whole text should be selected and when he starts typing text should be cleared. An example is browser address bar. Is there any way to do this?Please help me.

like image 425
user1767260 Avatar asked Nov 21 '12 04:11

user1767260


3 Answers

You can select all text in EditText by using

android:selectAllOnFocus and also setSelectAllOnFocus(boolean)

like image 152
Ram kiran Pachigolla Avatar answered Nov 18 '22 20:11

Ram kiran Pachigolla


Call EditText.setSelectAllOnFocus(boolean selectAllOnFocus) to select all text on focus.

Set a click listener to your EditText and in onClick call edittext.selectAll();

like image 6
Ronnie Avatar answered Nov 18 '22 21:11

Ronnie


Add attribute to your main.xml file:

android:selectAllOnFocus="true"

Then all text will be selected and when user type something that will remove it.

like image 3
Marcin S. Avatar answered Nov 18 '22 20:11

Marcin S.