Tooltip does not disappear when you click EditText

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 tooltip to disappear when the user clicks on it, but this will never happen. Please advise why.

+4
source share
2 answers

Try using onClickListener :

 editText.setOnClickListener(new OnClickListener { void onClick(View v) { editText.setHint(""); // or ((EditText) v).setHint("")); } }); 

To set the prompt 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, as long as there are no characters in the EditText , a tooltip is displayed.

+1
source

Maybe a slightly improved answer than @ NitroG42 ... Here is 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

+2
source

All Articles