How to use imeactionId value

I try to set my own imeActionId value and then compare it with actionId in onEditorAction . But the actionId in the method returns 0 many times.

 <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 here 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; } }); 

actionId becomes 0 each time, regardless of the value in XML. How to use my specific imeActionId to compare with actionId .

+6
source share
4 answers

Sorry for the late reply. Still sending my answer for the benefit of others. In fact, all and all kinds of interference got unqiueId. To accomplish your task, you can use the working code below.

 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 information, you can refer to this LINK . Hope you find this answer helpful.

+3
source

In fact, Android only recognizes certain actions that affect the appearance of the soft keyboard (for example, the presence of the DONE button). All such actions are listed here and they do not have the code 666. :)

Why do you need a special action? Know where it came from? Then just check the view id:

  public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (v.getId() == R.id.editText2) { // Whatever ... return true; } return false; } 

It will work!

+1
source

Using android:imeOptions="actionDone" works for me instead:

 <com.fiverr.fiverr.Views.FVREditText android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="textMultiLine" android:imeActionLabel="Create" android:imeActionId="@integer/editor_create_action_id" android:imeOptions="actionDone" android:lines="1" android:maxLines="2"/> 

And in the code:

 setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { customActionId = getResources().getInteger(R.integer.editor_create_action_id) if (actionId == customActionId) { onDonePressedRunnable.run(); } return false; } }); 
0
source

// this works for me

1- remove android:imeOptions="actionGo" from xml

2- also check the value of IME_NULL , since all these actions are treated as special keys, for example:

  if(actionId==666 || actionId == EditorInfo.IME_NULL){ ... } 

3- it is also better to use all resource files that are not hardcoded, for example, create a resource file in the values ​​folder that calls it ids.xml, and here is what it looks like:

 <?xml version="1.0" encoding="utf-8"?> <resources> <item type="id" name="r_login" format="integer">1001</item> </resources> 

and then your layout xml file should look like this:

 android:imeActionId="@id/r_browse" 

and your activity code should look like this:

 if(actionId==R.id.r_browse || actionId == EditorInfo.IME_NULL){ ... } 

Greetings;)

-2
source

Source: https://habr.com/ru/post/972497/


All Articles