3

I need a listener's to detect user interaction on my activity which has a fragment attached to it, for which i have overriden diapatchTouchEvent() which is working fine for touch event and hard key events, but it does not work for soft keyboard keypress.

To intercept keyboard touch events i have tried onUserInteraction(), dispatchKeyEvents(), onKeyUp, onKeyDown but none of them is working for softkeyboard.

Is there any other way to intercept softkeyboard events in Android?

for above query i have gone through these links :

https://stackoverflow.com/a/25620981/3954050

Android SoftKeyboard onKeyDown/Up not detecting 'alternative' keys

Community
  • 1
  • 1
Tushar Purohit
  • 524
  • 7
  • 25

1 Answers1

1

If you want to intercept keyboard event like done, or search or enter etc, in your edit text add a imeOption like

<EditText
   ..../
  android:id="@+id/myEditText"
  android:imeOptions="actionSearch"/>

And add an EditorActionListener to that edit text.

myEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            boolean handled = false;
            if (actionId == EditorInfo.IME_ACTION_SEARCH){
                //Do something
            }
Shashank Udupa
  • 2,173
  • 1
  • 19
  • 26