1

my key code in a row

<Key android:codes="49" android:keyLabel="1"  android:verticalGap="2%p"  android:popupKeyboard="@xml/popupview" android:popupCharacters="wW" android:keyEdgeFlags="left"/>

it show a popup window with 'w' and 'W' and a cross button when long press on '1'. but there is no action listener added to those character. If i click 'w' nothing happen but cross button works. But how can i add action listener to this character. thanks in advance :)

  • your code is your value. it automatically adds this to inputMethod of keyboard . if you want to do a different operation on this key change the code. – Zar E Ahmer Feb 09 '15 at 08:30
  • sorry bro i don't get what you try to explain. Please can you explain a little more? @Nepster –  Feb 11 '15 at 05:29

2 Answers2

0

My Solution: OnCreate:

 mKeyboardView.setOnKeyboardActionListener(new ActionListener(
            Activity.this,edittext, mKeyboardView));

 public class BasicOnKeyboardActionListener implements KeyboardView.OnKeyboardActionListener {

    EditText editText;
    CustomKeyboardView displayKeyboardView;
    private Activity mTargetActivity;

    public ActionListener(Activity targetActivity, EditText editText,
                                         CustomKeyboardView
                                                 displayKeyboardView) {
        mTargetActivity = targetActivity;
        this.editText = editText;
        this.displayKeyboardView = displayKeyboardView;
    }
      @Override
      public void onText(CharSequence text) {
        int cursorPosition = editText.getSelectionEnd();
        String previousText = editText.getText().toString();
        String before, after;
        if (cursorPosition < previousText.length()) {
            before = previousText.substring(0, cursorPosition);
            after = previousText.substring(cursorPosition);
        } else {
            before = previousText;
            after = "";
        }
        editText.setText(before + text + after);
        editText.setSelection(cursorPosition + 1);
       }

    @Override
    public void onKey(int primaryCode, int[] keyCodes) {
        switch (primaryCode) {
            case xx:// xx is primaryCode that is given program for pressed key
                onText("C");// C is char what you want to write
            default:                   
            break;
        }
    }
}
Meh yit
  • 14
  • 4