Search code examples
androidandroid-input-method

How to show suggest from input methods in an EditText?


I'm not implementing an input method, but trying to get the input state in my app. When we use 9-key mode, type 1~9 and there will be some hint. When using default input method in iOS hint will be in the EditText before you choose any suggest. I wonder whether android can get same effect.

For example, I intend to type "good", so i need to type 4663. First I type 4, the suggest gives me "h" and choices are "hi", "in", "I", "IT" and so on. Then I type 6, the suggest gives me "in" and choices are "in, gmail, iOS" and so on. Then type 6, suggest is "goo", choices are "good, home, honey". At last type 3, suggest is "good" and choices are "good, home, honey".

What I want is to have the hint in the EditText. If I type "466", I have "goo" in the EditText.

I browsed InputMethodManager API and related source code and found nothing. I can only use getInputMethodList() method to get InputMethodInfo. But I don't know how to get InputMethodService use InputMethodInfo. And also I don't know with which API I can get the suggest from InputMethodService(I guess I could get it from InputMethodService). Is it possible to do such thing in Android? If not, why?


Solution

  • It's impossible without adding a new input method. A client app can't get what an input method get. You can only determine what input method you are using, but can never get an instance of it.

    In KeyEvent.java it even says, "You should never rely on receiving KeyEvents for any key on a soft input method. In particular, the default software keyboard will never send any key event to any application targetting Jelly Bean or later, and will only send events for some presses of the delete and return keys to applications targetting Ice Cream Sandwich or earlier. Be aware that other software input methods may never send key events regardless of the version."