From: Kteby Date: Thu, 28 Jan 2016 07:03:34 +0000 (+0300) Subject: Hide virtual keyboard if searchView text was changed programatically. X-Git-Url: http://gitweb.fperrin.net/?p=Dictionary.git;a=commitdiff_plain;h=5f665bc8b167e306d5031a402ecadd4a3a54f64b Hide virtual keyboard if searchView text was changed programatically. --- 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); }