我已经将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 回答
- 1 回答
- 0 关注
- 211 浏览
添加回答
举报
0/150
提交
取消