亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

KeyPress / EditorAction事件處理程序被多次調用

KeyPress / EditorAction事件處理程序被多次調用

C#
精慕HU 2021-05-07 14:16:27
我已經將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 關注
  • 222 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號