// assuming you have a EditText view with id
View viewById = getView().findViewById(R.id.editTextId);
if(viewById!=null) {
// set listener to this view "many views could share one listener"
viewById.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
// if view match id && has no focus
if(v.getId() == R.id.editTextId && !hasFocus)
// clear hint
((EditText) v).setHint(null);
// else show hint
}
});
}
< HasFocus - а название говорит
- имеет (правда) -> показать
- не имеет (ложь) -> скрыть
, если вы не уверены, если view by id - это тот, который вы назначаете редактируемому тексту, выполните проверку (двойная проверка не повредит)
if (EditText.class.isAssignableFrom(v.getClass()))
// do cast
EditText editText = (EditText) v;
Этот код верный. Но. Как скрыть hinttext, после закрытия softkeyboard .. EditText имеют фокус - Eugenu Янского
Detecting when user has dismissed the soft keyboard
How to remove focus without setting focus to another control?
How to clear focus and remove keyboard on Android?
Этот код является правильным. Но. Как скрыть hinttext, после закрытия softkeyboard .. edittext имеют фокус –
переместить фокус на следующий элемент, очистить фокус - это ваш выбор :) см. Править – ceph3us
Хорошо, спасибо. ;-) –