最近因为项目需要,需要将EditText的焦点转移到LineraLayout上: 即为EditText输入完毕后,点击回车键或者按压其他嵌入式android设备的OK键,获取LineraLayout的点击事件。
在onCreate方法中调用此方法initListener即可;
/**
* 监听EditText的焦点,点击回车键(或者按压OK键)后,失去焦点,将焦点转到ImageView上
*/
private void initListener() {
mEtTrainId.setOnEditorActionListener(new TextView.OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEND
|| (event != null && event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
mEtTrainId.setFocusable(false);
mllFunction.setFocusable(true);
mllFunction.requestFocus();
mllFunction.findFocus();
return true;
}
return false;
}
});
}