Skip to content

Instantly share code, notes, and snippets.

@gsysko
Last active May 15, 2017 09:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save gsysko/d46adbe27d409bde0299 to your computer and use it in GitHub Desktop.
Save gsysko/d46adbe27d409bde0299 to your computer and use it in GitHub Desktop.
Setting imeActionId with a predefined ID resource creates an error.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@id/editText"
android:layout_alignParentLeft="true"
android:inputType="text"
android:imeActionId="@id/action_sign_in"
android:imeActionLabel="@string/sign_in_short"/>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item type="id" name="action_sign_in"/>
<item type="id" name="editText"/>
</resources>
package com.me.keyboard.test;
import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
EditText editText = (EditText) findViewById(R.id.editText);
//Interestingly, it works if I instead set the actionID programatically....
//editText.setImeActionLabel(getResources().getString(R.string.sign_in_short), R.id.action_sign_in);
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == R.id.action_sign_in)
{
Toast.makeText(getApplicationContext(), "Sent", Toast.LENGTH_LONG).show();
return true;
}
return false;
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment