Android Studio提交回车

时间:2015-06-29 13:40:14

标签: java android android-studio

我正在使用Android Studio使用Motorola CS3000条形码扫描仪为Android创建应用。它处于HID模式(模拟键盘),每次扫描它输入一系列键,并以回车结束。

我正在使用onEditorActionListener来触发事件,并且想知道如何通过从扫描仪回车来触发所述事件。

1 个答案:

答案 0 :(得分:1)

@Override
public boolean onEditorAction(TextView textView, int actionId, KeyEvent event) {

    if (event != null && event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {

        switch (event.getAction()) {

        case KeyEvent.ACTION_DOWN:
            // for some reason we can get tons of repeated down events in the debugger, maybe from keyboard auto-repeat?
            return true;

        case KeyEvent.ACTION_UP:

            // *** put your event code here ***

            return true;
        }

    }
}
相关问题