Android 如何在活动开始时清除物理键盘缓冲区
我想在活动开始时清除物理键。我有一个活动,当用户在EditText上单击Enter时,它会打开另一个活动。下面的函数checkAnswer()将显示一个新活动。它可以与软键配合使用。但是使用物理密钥,不需要的输入将发送到新活动Android 如何在活动开始时清除物理键盘缓冲区,android,Android,我想在活动开始时清除物理键。我有一个活动,当用户在EditText上单击Enter时,它会打开另一个活动。下面的函数checkAnswer()将显示一个新活动。它可以与软键配合使用。但是使用物理密钥,不需要的输入将发送到新活动 @Override public boolean onEditorAction(TextView view, int actionId, KeyEvent event) { if (event==null) { if ((actionId != E
@Override
public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
if (event==null) {
if ((actionId != EditorInfo.IME_ACTION_DONE) && (actionId != EditorInfo.IME_ACTION_NEXT)) {
return false;
}
}
else {
if (actionId == EditorInfo.IME_NULL) {
if (event.getAction()==KeyEvent.ACTION_UP) {}
else {
return true;
}
}
else {
return false;
}
}
checkAnswer();
return true;
}
我猜这是因为在onEditorAction()返回true之前调用了新活动,所以Android系统认为我的处理程序不使用enter,它将条目发送给新活动
@Override
public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
if (event==null) {
if ((actionId != EditorInfo.IME_ACTION_DONE) && (actionId != EditorInfo.IME_ACTION_NEXT)) {
return false;
}
}
else {
if (actionId == EditorInfo.IME_NULL) {
if (event.getAction()==KeyEvent.ACTION_UP) {}
else {
return true;
}
}
else {
return false;
}
}
checkAnswer();
return true;
}
只想在新活动开始时清除按键缓冲区。我仍然想在新活动中使用键盘,我只是不想收到呼叫者按的不需要的enter键。我仍然想在新活动中使用键盘,我只是不想收到呼叫者按的不需要的enter键。
public static void hideKeyboard(Activity activity) {
InputMethodManager imm = (InputMethodManager)
activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
//Find the currently focused view, so we can grab the correct window token from it.
View view = activity.getCurrentFocus();
//If no view currently has focus, create a new one, just so we can grab a window
token from it
if (view == null) {
view = new View(activity);
}
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}