DatabaseManager_For_Android icon indicating copy to clipboard operation
DatabaseManager_For_Android copied to clipboard

Close soft keyboard upon executing SQL query or tapping elsewhere

Open SpencerY2 opened this issue 10 years ago • 8 comments

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!!

SpencerY2 avatar Jan 23 '15 14:01 SpencerY2

Thanks... will add this to the code

sanathp avatar Jan 23 '15 15:01 sanathp

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

SpencerY2 avatar Jan 23 '15 16:01 SpencerY2

getting error on Line 830 of AndroidDatabaseManager.java as "lcrud.setId(299)"

Error: expect resource of type id.

kiran-pathe avatar Feb 06 '15 06:02 kiran-pathe

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);

sanathp avatar Feb 06 '15 06:02 sanathp

nope. I have latest version of android studio. it did not solved my problem.

what is that 299 ???

kiran-pathe avatar Feb 06 '15 06:02 kiran-pathe

I have sent you chat request on gmail. Please accept it and help me to solve my problem.

kiran-pathe avatar Feb 06 '15 06:02 kiran-pathe

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.

sanathp avatar Feb 06 '15 06:02 sanathp

replace lcrud.setId(299); with int my_var=0; my_var=my_var+299; lcrud.setId(my_var);

solve error

ishfaqhaider avatar May 25 '15 06:05 ishfaqhaider