Skip to content Skip to sidebar Skip to footer

Xamarin.android: Key Listener Not Working

In the OnCreate fragment method, I get my EditText from the layout and call SetOnKeyListener: Aaa = view.FindViewById(Resource.Id.aaaText); Aaa.SetOnKeyListener(new

Solution 1:

Although this is an old topic, but I ran into the same issue, just be aware that View.IOnKeyListener does not support SoftKeyboard (virtual keyboard) key inputs. Only hardware keyboard input is performed via OnKey event.

Depending on your usecase, if you want to get notified if E.g. any softkeyboard button is pressed (like Keycode.NavigateNext button) than use EditorAction event. In Xamarin.Forms E.g. define a custom entry renderer and in the OnElementChanged event listen on the event via:

this.EditText.EditorAction += EditTextOnEditorAction;

Than handle any key action which your are interested in:

privatevoidEditTextOnEditorAction(object sender, TextView.EditorActionEventArgs e)
{
    if (e.ActionId == ImeAction.Next)
    {
        var formsNextSearch = FocusSearchNextElement();
        if (formsNextSearch != null)
        {
            EditText.ClearFocus();                   
        }
    }
}

Android Keyboard-Input docu

Post a Comment for "Xamarin.android: Key Listener Not Working"