I'm trying to handle the Enter
button on Android soft keyboard. I tried what it's said in this post also from StackOverflow, but with no luck.
I have two EditText
fields: one that asks for user name and the other for the user email. When I complete the username, I want to perform a Next
action and go down to the next EditText
.
This is my .xml file:
<EditText android:layout_width="fill_parent" android:layout_height="wrap_content"
android:id="@+id/text_user_name" android:layout_marginTop="20dp"
android:layout_marginLeft="10dp" android:layout_marginRight="10dp"
android:layout_weight="1"
android:imeOptions="actionNext"
android:inputType="text"
android:nextFocusDown="@+id/text_user_email"
android:hint="name"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@id/text_user_email"
android:layout_marginTop="20dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:imeOptions="actionDone"
android:hint="***@email.com"/>
This is my OnEditorActionListener
:
return new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if(actionId == EditorInfo.IME_ACTION_DONE && event.getKeyCode() == KeyEvent.KEYCODE_ENTER){
if (!finished)
{
// Check user information
if (CheckUserInfo()) finished = true;
}
return true;
}
else
if (actionId == EditorInfo.IME_ACTION_NEXT && event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
Toast.makeText(getApplicationContext(), "go a line down", Toast.LENGTH_SHORT).show();
return true;
}
else
{
return false;
}
}
};
I tried also to change the visible text for the Enter
button, to look like a Next
for the first EditText
and as a Done
for the final EditText
like this:
textUserName.setImeActionLabel("Next", KeyEvent.KEYCODE_ENTER);
....
textUserEmail.setImeActionLabel("Done", KeyEvent.KEYCODE_ENTER);
But this part is not working either.
Can anybody help me understand why I can't make anything work? :_( Thanks!