我想要检测何时按下软键“完成”,以便在此时显示烤面包消息。我看到这个帖子提出了同样的问题here但是,我很困惑如何实施解决方案。Android:按下软按键上的“完成”键时检测
提供的解决方案是:
editText = (EditText) findViewById(R.id.edit_text);
editText.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
// toast message
}
return false;
}
});
我的问题是这样的:
- 是EDITTEXT假设onCreate方法下被定义?
- 是整个代码假设是在onCreate方法?