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