Reputation: 1961
I have a Xamarin.Android application and running into an issue where events on an EditText field aren't firing on my device. They work on the simulator but not my Nexus 5X. Any Thoughts?
Layout
<EditText
android:id="@+id/usernameTextField"
android:layout_width="0dp"
android:layout_height="wrap_content"
style="@style/LoginTheme.EditText"
android:background="@android:color/transparent"
android:hint="user name"
android:lines="1"
android:maxLines="1"
app:layout_constraintTop_toBottomOf="@id/topBorder"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintWidth_max="350dp" />
Code
UsernameTextField = FindViewById<EditText> (Resource.Id.usernameTextField);
PasswordTextField = FindViewById<EditText> (Resource.Id.passwordTextField);
UsernameTextField.KeyPress += (sender, e) => {
if (e.KeyCode == Keycode.Enter && e.Event.Action == KeyEventActions.Down) {
this.PasswordTextField.RequestFocus();
}
};
UsernameTextField.KeyPress += (sender, e) => {
if (e.KeyCode == Keycode.Enter && e.Event.Action == KeyEventActions.Down) {
this.PasswordTextField.RequestFocus();
}
};
PasswordTextField.KeyPress += (sender, e) => {
if (e.KeyCode == Keycode.Enter && e.Event.Action == KeyEventActions.Down) {
this.DoLogin ();
}
};
I have also tried using IME actions such as this.
UsernameTextField.EditorAction += HandleEditorAction;
PasswordTextField.EditorAction += HandleEditorAction;
private void HandleEditorAction(object sender, TextView.EditorActionEventArgs e) {
e.Handled = false;
if (e.ActionId == ImeAction.Send) {
}
}
Nothing seems to work. When I hit the enter button on the virtual keyboard it just creates a new line in the EditText field. Any ideas?
Upvotes: 2
Views: 888
Reputation: 1961
And as usual five minutes after posting this I found the solution. For whatever reason adding and inputType to the EditText seems to fix the problem and the KeyPress events are now working. Maybe this is a bug within Xamarin?
Upvotes: 3