Connecting a view with the Inputmethod

I have created a custom view by extending the View class. On click I want the soft keyboard to pop up, just like it would with an edittext (ie with predictive text turned on and with the ability to select all available input methods).

I have tried having the view extend an onclicklistener that, when called, uses InputMethodManager to display the soft keyboard, which then in turn uses Onkeydown to intercept key presses. This is clunky and doesn't work because:

  • I'm only able to switch between standard text and numerical input methods. No other input methods work (I need to be able to switch to the Japanese IME if a user has one, just like an edittext).

  • There's no predictive text, which is absolutely necessary for the program as it will need users to enter japanese kanji.

  • Is there any way to set up a connection between a standard view and the IME similar to an edittext?


    To show the predictive text,you should set the EditorInfo type which can be accepted by the system. Something like this:

    @Override
    public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
           // TODO Auto-generated method stub
           // Set your EditorInfo type in the onCreateInputConnection
           outAttrs.actionLabel = null;
           outAttrs.inputType = InputType.TYPE_CLASS_TEXT;
           outAttrs.imeOptions = EditorInfo.IME_ACTION_NEXT;
           return new MyBaseInputConnection(this, false);
    }
    
    链接地址: http://www.djcxy.com/p/93022.html

    上一篇: Android多行EditText

    下一篇: 用Inputmethod连接一个视图