From 5f665bc8b167e306d5031a402ecadd4a3a54f64b Mon Sep 17 00:00:00 2001 From: Kteby Date: Thu, 28 Jan 2016 10:03:34 +0300 Subject: [PATCH] Hide virtual keyboard if searchView text was changed programatically. --- .../android/dictionary/DictionaryActivity.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/com/hughes/android/dictionary/DictionaryActivity.java b/src/com/hughes/android/dictionary/DictionaryActivity.java index bd45672..c8d99e4 100644 --- a/src/com/hughes/android/dictionary/DictionaryActivity.java +++ b/src/com/hughes/android/dictionary/DictionaryActivity.java @@ -638,6 +638,13 @@ public class DictionaryActivity extends ActionBarActivity { } } + private void hideKeyboard() { + Log.d(LOG, "Hide soft keyboard."); + searchView.clearFocus(); + InputMethodManager manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); + manager.hideSoftInputFromWindow(searchView.getWindowToken(), 0); + } + void updateLangButton() { final LanguageResources languageResources = DictionaryApplication.isoCodeToResources.get(index.shortName); @@ -1006,7 +1013,7 @@ public class DictionaryActivity extends ActionBarActivity { getListView().requestFocus(); // Visual indication that a new keystroke will clear the search text. - // Doesn't seem to work unless earchText has focus. + // Doesn't seem to work unless searchText has focus. // searchView.selectAll(); } @@ -1109,6 +1116,9 @@ public class DictionaryActivity extends ActionBarActivity { searchView.setIconifiedByDefault(text.length() > 0); searchView.setIconified(false); + // We don't want to show virtual keyboard when we're changing searchView text programatically: + hideKeyboard(); + if (triggerSearch) { onQueryTextListener.onQueryTextChange(text); } -- 2.43.0