-3

I developed a soft keyboard for Android, and I want to enter text into my own EditText on the keyboard's main screen.

If I add an EditText to the keyboard Layout it is not receiving input from the keyboard (Neither if I put it in a Dialog or a PopupWindow). Also requestFocus, setFocusable, etc are not helping.

The only way an EditText receives the keyboard input is if I put it in a new Activity (which is not what I need). AI-Type Keyboard has done this. They allow Google Search from within the keyboard.

Any ideas?

default
  • 11,485
  • 9
  • 66
  • 102
Alon Shmiel
  • 6,753
  • 23
  • 90
  • 138

1 Answers1

1

I had the same problem. Immediately after editText VISABILITY change from GONE to VISIBLE, I had to set the focus and display the soft keyboard. I achieved this using the following code:

(new Handler()).postDelayed(new Runnable() {

    public void run() {
//      ((EditText) findViewById(R.id.et_find)).requestFocus();
//      
        EditText yourEditText= (EditText) findViewById(R.id.et_find);
//      InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
//      imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT);

        yourEditText.dispatchTouchEvent(MotionEvent.obtain(
            SystemClock.uptimeMillis(), SystemClock.uptimeMillis(),
            MotionEvent.ACTION_DOWN , 0, 0, 0));
        yourEditText.dispatchTouchEvent(MotionEvent.obtain(
            SystemClock.uptimeMillis(), SystemClock.uptimeMillis(),
            MotionEvent.ACTION_UP , 0, 0, 0));                       

    }
}, 200);

It works for me with 100ms delay, but failed without any delay or with only a delay of 1ms.

Commented part of code shows another approach, which works only on some devices. I tested on OS versions 2.2 (emulator), 2.2.1 (real device) and 1.6 (emulator).

This approach saved me a lot of pain.

A.L
  • 10,259
  • 10
  • 67
  • 98
  • Didn't work in inside edittext which is above keyboardview . I have problem like this [question](https://stackoverflow.com/questions/55176159/gboard-like-search-bar-in-android-ime) help us if u can. – Bhavin Patel Jul 24 '19 at 10:09