2015-06-29 16 views
1

我正在使用Android Studio爲使用Motorola CS3000條形碼掃描儀的Android Studio創建應用。它處於HID模式(仿真鍵盤),並且每次掃描都會輸入一系列按鍵,並以回車結束。Android Studio在回車中提交

我正在使用onEditorActionListener觸發事件,並想知道如何通過從掃描儀回車來觸發所述事件。

回答

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; 
     } 

    } 
} 
+0

工作就像一個魅力。謝謝 – KGillis

+0

太棒了!如果您接受我的回答是正確的,我將不勝感激。乾杯 –

+0

剛做過。第一次問一個問題,所以我沒有意識到這個檢查標記。 – KGillis