0

I am developing custom keyboard using by extend InputMethodService and implemented OnKeyboardActionListener. I am catching all the keyevent in a class where I am getting all the event of each keys and performing the action.

public class SimpleIME extends InputMethodService implements
    OnKeyboardActionListener {

private KeyboardView kv;
private Keyboard keyboard;
private boolean caps = false;


@Override
public void onKey(int primaryCode, int[] keyCodes) {
    InputConnection ic = getCurrentInputConnection();
    playClick(primaryCode);
    switch(primaryCode){
    case Keyboard.KEYCODE_DELETE :
        ic.deleteSurroundingText(1, 0);
        break;
    case Keyboard.KEYCODE_SHIFT:
        caps = !caps;
        keyboard.setShifted(caps);
        kv.invalidateAllKeys();
        break;
    case Keyboard.KEYCODE_DONE:
        ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER));
        break;
    default:
        char code = (char)primaryCode;
        if(Character.isLetter(code) && caps){
            code = Character.toUpperCase(code);
        }
        ic.commitText(String.valueOf(code),1);                  
    }
}

My Querty.xml is:

<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
android:horizontalGap="0px"
android:keyHeight="60dp"
android:keyWidth="10%p"
android:verticalGap="0px" >

<Row>
    <Key
        android:codes="81"
        android:keyEdgeFlags="left"
        android:keyLabel="Q" />
    <Key
        android:codes="87"
        android:keyLabel="W" />
    <Key
        android:codes="69"
        android:keyLabel="E" />
    <Key
        android:codes="82"
        android:keyLabel="R" />
    <Key
        android:codes="84"
        android:keyLabel="T" />
    <Key
        android:codes="89"
        android:keyLabel="Y" />
    <Key
        android:codes="85"
        android:keyLabel="U" />
    <Key
        android:codes="73"
        android:keyLabel="I" />
    <Key
        android:codes="79"
        android:keyLabel="O" />
    <Key
        android:codes="80"
        android:keyLabel="P" />

</Row>
<Row>
    <Key
        android:codes="65"
        android:keyEdgeFlags="left"
        android:keyLabel="A" />
    <Key
        android:codes="83"
        android:keyLabel="S" />
    <Key
        android:codes="68"
        android:keyLabel="D" />
    <Key
        android:codes="70"
        android:keyLabel="F" />
    <Key
        android:codes="71"
        android:keyLabel="G" />
    <Key
        android:codes="72"
        android:keyLabel="H" />
    <Key
        android:codes="74"
        android:keyLabel="J" />
    <Key
        android:codes="75"
        android:keyLabel="K" />
    <Key
        android:codes="76"
        android:keyLabel="L" />

</Row>
<Row>
    <Key
        android:codes="-5"
        android:isRepeatable="true"
        android:keyEdgeFlags="left"
        android:keyLabel="DEL"
        android:keyWidth="20%p" />
    <Key
        android:codes="90"
        android:keyLabel="Z" />
    <Key
        android:codes="88"
        android:keyLabel="X" />
    <Key
        android:codes="67"
        android:keyLabel="C" />
    <Key
        android:codes="86"
        android:keyLabel="V" />
    <Key
        android:codes="66"
        android:keyLabel="B" />
    <Key
        android:codes="78"
        android:keyLabel="N" />
    <Key
        android:codes="77"
        android:keyLabel="M" />
    <Key
        android:codes="-4"
        android:isRepeatable="true"
        android:keyEdgeFlags="right"
        android:keyLabel="DONE"
        android:keyWidth="20%p" />
</Row>

All are Ok. But I want ot use NEXT button in my keyboard instead of DONE button. I have used android:imeOptions="actionNext", android:singleLine="true" in my XML. But I am not able to send cursor to next EditText. What I have to change ?

1 Answers1

0

I do this inside my Activity, when i want that NEXT button to appear when i'm on EditText:

        courseCRN= (EditText) courseCRNLayout.findViewById(R.id.editText);
        View focusView = null;
        courseCRN.setImeActionLabel("NEXT",3);
        courseCRN.setPrivateImeOptions("actionUnspecified");
        courseCRN.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) {
                if (id == 3 || id == EditorInfo.IME_NULL) {
                   //focus on next View
                     focusView = yourNextView;  
                     focusView.requestFocus();
                    return true;
                }
                return false;
            }
        });
Jemshit
  • 9,501
  • 5
  • 69
  • 106