Close soft keyboard upon executing SQL query or tapping elsewhere
It would be nice if you could auto-dismiss the soft keyboard when the user clicks "Submit Query" or if they tap anywhere that is not a textView.
This code can be used:
public void setUpHideKeyboardListeners(View view) {
//Set up touch listener for non-text box views to hide keyboard.
if(!(view instanceof EditText)) {
view.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
hideSoftKeyboard(VoiceFragment.this.getActivity());
return false;
}
});
}
//If a layout container, iterate over children and seed recursion.
if (view instanceof ViewGroup) {
for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
View innerView = ((ViewGroup) view).getChildAt(i);
setUpHideKeyboardListeners(innerView);
}
}
}
Called as
setUpHideKeyboardListeners(view);
in OnCreateView();
To programmatically hide the keyboard:
public static void hideSoftKeyboard(Activity activity) {
View currentFocusView = activity.getCurrentFocus();
if (currentFocusView != null) {
InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(currentFocusView.getWindowToken(), 0);
}
}
and call it as something like:
hideSoftKeyboard(this);
or
hideSoftKeyboard(this.getActivity());
Thanks a lot for this contribution!!
Thanks... will add this to the code
Thanks!
On Fri, Jan 23, 2015 at 7:56 AM, Sanath Kumar [email protected] wrote:
Thanks... will add this to the code
— Reply to this email directly or view it on GitHub https://github.com/sanathp/DatabaseManager_For_Android/issues/3#issuecomment-71214260 .
Spencer Yeh
[email protected] mobile: 650-804-0926
getting error on Line 830 of AndroidDatabaseManager.java as "lcrud.setId(299)"
Error: expect resource of type id.
looks like you are using old version of android studio.... Check this solution on stackoverflow http://stackoverflow.com/questions/24716385/android-studios-expected-resource-of-type-checks
Try adding the below three lines in place of line 830.If this doesnt work search for more solutions on stack overflow: @LayoutRes int resourceId ; resourceId = 299; lcrud.setId(resourceId);
nope. I have latest version of android studio. it did not solved my problem.
what is that 299 ???
I have sent you chat request on gmail. Please accept it and help me to solve my problem.
Its just some random id you have assign to that layout. Remove that line and try once . If that does not work write a function as given in that stackoverflow url and set the value.
replace lcrud.setId(299); with int my_var=0; my_var=my_var+299; lcrud.setId(my_var);
solve error