我想要檢測何時按下軟鍵「完成」,以便在此時顯示烤麪包消息。我看到這個帖子提出了同樣的問題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方法?