William Da Silva
William Da Silva

Reputation: 723

Show/Hidden Soft Keyboard event in Android

I need to get the Show/Hidden event from the SoftKeyboard in Android.

I did a research, but nothing worked.

I wanted that 'cause we're working with a tablet 5.0'' with low resolution, so when you edit a EditText, the keyboard rise in full screen, and then or you press the "enter or next" key, or you press the back button to hide the keyboard... I need to update some fields with the new value, but I can't use the TextWatcher 'cause have some business logics on what's the right fields to update, and 'cause I just want to update when the user really finish the input.

And the onFocusChanged isn't a option, 'cause we don't want our customers needing to cliking in the next field, and hiding the keyboard to see the new values.

I don't want to override the onTouchEvent too, see if where the user cliked isn't the same field that he is editing.

Sorry for the specific problem and more specific solution that I'm asking for.

And sorry for my bad English :D

Upvotes: 1

Views: 7780

Answers (2)

Pawan Maheshwari
Pawan Maheshwari

Reputation: 15356

Use tree view observer to detect any change in view height and that time you can check whether keyboard state

                final View activityRootView = findViewById(R.id.chat_pane_root_view);
                activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener()
                {
                    @Override
                    public void onGlobalLayout()
                    {
                        InputMethodManager mgr = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
                        if(mgr.isAcceptingText())
                        {
                             //keyboard is up
                        }
                    }
                });

Upvotes: 4

user1496130
user1496130

Reputation:

First of all in your declairation of your activity in manifest file declaire like this

<activity android:name="Map"  android:windowSoftInputMode="stateHidden">

from this property your keyboard is being hidden, after this you are declaire the imeOption property in your main.xml file edittext like this

<EditText
                    android:id="@+id/edttexttitle"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="5dp"
                    android:layout_marginTop="5dp"
                    android:hint="@string/tasktitle"
                    android:imeOptions="actionNext"
                    android:inputType="text"
                    android:textSize="@dimen/font_size_medium"
                    android:textColor="@color/darkgray1" />

this code is for your first edittext if more then one and if only one edittext then your need to change the imeOption of edittext like

android:imeOptions="actionGo"

Upvotes: -1

Related Questions