I'm trying to handle a keyboard response:
EditText editText = (EditText) findViewById(R.id.password);
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
boolean handled = false;
Log.d(TAG, "IME_ACTION_GO int:"+ IME_ACTION_GO+ " action id: "+ actionId);
if (actionId == IME_ACTION_GO) {
handled = true;
Toast toast = Toast.makeText(getApplicationContext(),"GO pressed", Toast.LENGTH_SHORT);
toast.show();
}
return handled;
}
});
and my layout xml is :
<EditText
android:id="@+id/password"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:hint= "Password"
android:inputType="textPassword"
android:layout_alignBottom="@+id/button"
android:layout_alignLeft="@+id/user_name"
android:layout_alignStart="@+id/user_name"
android:singleLine="true"
android:imeOptions="actionGo"
android:imeActionLabel="Login"/>
However, the actionID is always 0, whereas the int value for IME_ACTION_GO is 2. Therefore the if statement is never true.