In Android how can I make an EditText
clear when it's clicked?
E.g., if I have an EditText
with some characters in, such as 'Enter Name'
, when the user clicks on it these characters disappear.
In Android how can I make an EditText
clear when it's clicked?
E.g., if I have an EditText
with some characters in, such as 'Enter Name'
, when the user clicks on it these characters disappear.
after onclick of any action do below step
or
write this in XML file
its works fine for me. Hope to you all.
that is called hint in android use android:hint="Enter Name"
Be careful when setting text with an onClick listener on the field you are setting the text. I was doing this and setting the text to an empty string. This was causing the pointer to come up to indicate where my cursor was, which will normally go away after a few seconds. When I did not wait for it to go away before leaving my page causing finish() to be called, it would cause a memory leak and crash my app. Took me a while to figure out what was causing the crash on this one..
Anyway, I would recommend using selectAll() in your on click listener rather than setText() if you can. This way, once the text is selected, the user can start typing and all of the previous text will be cleared.
pic of the suspect pointer: http://i.stack.imgur.com/juJnt.png
For me the easiest way... Create an public EditText, for Example "myEditText1"
Then, connect it with the EditText which should get cleared
After that, create an void which reacts to an click to the EditText an let it clear the Text inside it when its Focused, for Example
Hope i could help you, Have a nice Day everyone