本文整理汇总了Java中android.inputmethodservice.KeyboardView.OnKeyboardActionListener类的典型用法代码示例。如果您正苦于以下问题:Java OnKeyboardActionListener类的具体用法?Java OnKeyboardActionListener怎么用?Java OnKeyboardActionListener使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OnKeyboardActionListener类属于android.inputmethodservice.KeyboardView包,在下文中一共展示了OnKeyboardActionListener类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initKeyboard
import android.inputmethodservice.KeyboardView.OnKeyboardActionListener; //导入依赖的package包/类
private void initKeyboard() {
keyboard = new Keyboard(this, R.xml.keyboard);
keyboardView = (KeyboardView) findViewById(R.id.keyboardview);
keyboardView.setKeyboard(keyboard);
keyboardView.setPreviewEnabled(false);
OnKeyboardActionListener mOnKeyboardActionListener = new OnKeyboardActionListener() {
@Override
public void onKey(int code, int[] keyCodes) {
String str = textForKeyboard.getText().toString();
switch (code) {
case Constants.KEY_CODE_BACK:
if (!str.isEmpty()) {
textForKeyboard.setText(str.substring(0,
str.length() - 1));
}
break;
case Constants.KEY_CODE_ENTER:
checkAnswer(str);
break;
default:
if (str.length() < sNumberlength) {
textForKeyboard.setText(str + code);
}
}
}
@Override
public void onPress(int arg0) {
}
@Override
public void onRelease(int primaryCode) {
}
@Override
public void onText(CharSequence text) {
}
@Override
public void swipeDown() {
}
@Override
public void swipeLeft() {
}
@Override
public void swipeRight() {
}
@Override
public void swipeUp() {
}
};
keyboardView.setOnKeyboardActionListener(mOnKeyboardActionListener);
openKeyboard();
}