I have an EditText
:
<EditText
android:hint="Your Notes" android:id="@+id/tv_notes_data"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:gravity="right" style="@style/items_description_plain" />
I need the hint to disappear when user clicks on it, but this never happen. Please advice why.
Maybe a lightly improved answer than @NitroG42's... Here's my solution:
editText.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
editText.setHint("");
return false;
}
});
editText.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus){
editText.setHint("Hint");
}
}
});
hope this helps someone
Try to use an onClickListener
:
editText.setOnClickListener(new OnClickListener {
void onClick(View v) {
editText.setHint("");
// or ((EditText) v).setHint(""));
}
});
For setting the hint again, you can use:
editText.setOnFocusChangeListener(new OnFocusChangeListener {
void OnFocusChange(params) {
editText.setHint("Your Notes");
}
});
By the way, the hint disappears only when the user starts typing. In fact, while there is no characters in the EditText
, the hint is shown.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With