I have a scenario, for example, a EditText in acitivity instead 开发者_如何学Goof using Textview as a label of it i want to put text "UserName" inside EditText and if user clicks on it. it should disappear and EditText should get empty to enter data in it.
How can I achieve this?
android:hint="username"
put this attribute in EditText
thats it.
onclickListener does not work with EditText items, you'll have to use an OnFocusListener.
Use setOnClickListener()
to register a listener that then checks if the EditText just contains "UserName", and clears it out if that is true.
精彩评论