您好希望我的问题是相当自我解释的。
但是要详细说明,我希望能够告诉我的程序即使它没有按下已完成的键。希望这只是两行代码中的一行。
答案 0 :(得分:2)
您可以通过向EditText添加OnKeyListener来实现此目的,以下是代码段:
myEditText.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
if (keyCode == KeyEvent.KEYCODE_ENTER) {
// The "done" key is pressed, handle the event here.
}
return false;
}
});
您还可以通过将OnEditorActionListener设置为EditText来实现此目的。这是代码:
myEditText.setImeOptions(EditorInfo.IME_ACTION_DONE);
myEditText.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView arg0, int keycode, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
// The "done" key is pressed, handle the event here.
}
return false;
}
});