I am trying to set my own value to imeActionId
and then comparing the same to the actionId
in the onEditorAction
. But the actionId
in the method repeatedly returns 0.
<EditText
android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="text|textUri"
android:imeOptions="actionGo"
android:imeActionId="666"
android:imeActionLabel="google"/>
And the following is my onEditorAction
:
et.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
// TODO Auto-generated method stub
Log.v("myid iss", "" + actionId);
if(actionId == 666)
{
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("http://" + v.getText().toString()));
imm.hideSoftInputFromInputMethod(v.getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY);
startActivity(i);
}
return false;
}
});
The actionId
is coming to be 0 every time irrespective of the value in the XML.
How do I use my defined imeActionId
to compare with actionId
.
Sorry for late reply. Still posting my answer for the benefit of others. Actually, each and every imeoptions got a unqiueId. In order perform your task, you can make use of below working code.
editText.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
boolean handled = false;
if (actionId == EditorInfo.IME_ACTION_GO) {
//Perform your Actions here.
}
return handled;
}
});
For more info, you can refer this LINK. Hope you find this answer usefull.
Actually Android recognises only specific actions which affect the appearance of soft keyboard (e.g. presence of DONE button). All such actions are listed here and neither has code 666. :)
What do you need a custom action for? To know where it comes from? Then just check view id:
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (v.getId() == R.id.editText2) {
// Whatever ...
return true;
}
return false;
}
This will certainly work!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With