我已經將EditText控件的事件處理程序Keypress和EditorAction事件處理程序組合到一個稱為InputField_KeyPressEditorAction的方法中。當我輸入一些文本并按Enter時,以下代碼將執行多次(2、3或更多次):private void InputField_KeyPressEditorAction(object sender, EventArgs e) { var ke = e as View.KeyEventArgs; var eae = e as TextView.EditorActionEventArgs; if (ke != null) { ke.Handled = false; } if (eae != null) { eae.Handled = false; } if (ke != null && (ke.Event.Action == KeyEventActions.Down || ke.Event.Action == KeyEventActions.Up) && (ke.KeyCode == Keycode.Enter || ke.KeyCode == Keycode.Unknown) || eae != null && eae.ActionId == ImeAction.Done) { if (string.IsNullOrEmpty(_inputField.Text)) return; _inputField.Text = Regex.Replace(_inputField.Text, @"\t|\n|\r", string.Empty); if (_notificationArea.Text.Contains(_scanEan)) { // Following code executes twice.... } if (ke != null) { ke.Handled = true; } if (eae != null) { eae.Handled = true; } var imm = (InputMethodManager)GetSystemService(InputMethodService); imm.HideSoftInputFromWindow(CurrentFocus.WindowToken, HideSoftInputFlags.None); } }我將事件處理程序分配給控件的部分: _inputField = FindViewById<EditText>(Resource.Id.editTextScan); _inputField.KeyPress += InputField_KeyPressEditorAction; _inputField.EditorAction += InputField_KeyPressEditorAction;這種奇怪行為的原因是什么?難道我做錯了什么?
- 1 回答
- 0 關注
- 222 瀏覽
添加回答
舉報
0/150
提交
取消