所以这是我的问题,我的代码工作正常,当我从我的物理键盘按空间时,它会按照预期进行操作,但是当我按下软键盘上的空格时,它不起作用。我尝试使用KEYCODE_ENTER运行我的代码,它实际上在硬键盘和软键盘上都能正常工作。
这是我的代码:
editTextInput.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if ((event.getAction() == KeyEvent.ACTION_UP) && (keyCode == KeyEvent.KEYCODE_SPACE)) {
//If paragraph contains the word then it returns true, thus increasing wordCount by 1
if(paragraphToArray(testParagraph,search) == true)
{
wordCount += 1;
}
if(wordCount == 1)
{
startTimer();
}
//Clearing the editTextInput edit area.
editTextInput.setText("");
//search = "";
search.replace(0,30,"");
return true;
}
return false;
}
});