У меня есть EditText с составной прорисовкой справа. Я хочу спрятать программную клавиатуру, когда я нажимаю на нарисованный и очищаю текст. Для этого у меня есть следующий код:
filterText.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (filterText.getCompoundDrawables()[2] == null) {
// cross is not being shown so no need to handle
return false;
}
if (event.getAction() != MotionEvent.ACTION_DOWN) {
// only respond to the down type
return false;
}
if (event.getX() > filterText.getMeasuredWidth() -
filterText.getPaddingRight() - d.getIntrinsicWidth()) {
filterText.setText("");
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
return false;
}
else {
return true;
}
}
});
Но это не работает, потому что editText, кажется, поддерживает фокус. Я пытался отфильтровать текст.clearFocus, но не смог.
Спасибо