I am having an EditText
where I am setting the following property so that I can display the done button on the keyboard when user click on the EditText.
editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
When user clicks the done button on the screen keyboard (finished typing) I want to change a RadioButton
state.
How can I track done button when it is hit from screen keyboard?
then,java code is,
Thanks to chikka.anddev in Kotlin it is:
While most people have answered the question directly, I wanted to elaborate more on the concept behind it. First, I was drawn to the attention of IME when I created a default Login Activity. It generated some code for me which included the following:
You should already be familiar with the inputType attribute. This just informs Android the type of text expected such as an email address, password or phone number. The full list of possible values can be found here.
It was, however, the attribute
imeOptions="actionUnspecified"
that I didn't understand its purpose. Android allows you to interact with the keyboard that pops up from bottom of screen when text is selected using theInputMethodManager
. On the bottom corner of the keyboard, there is a button, typically it says "Next" or "Done", depending on the current text field. Android allows you to customize this usingandroid:imeOptions
. You can specify a "Send" button or "Next" button. The full list can be found here.With that, you can then listen for presses on the action button by defining a
TextView.OnEditorActionListener
for theEditText
element. As in your example:Now in my example I had
android:imeOptions="actionUnspecified"
attribute. This is useful when you want to try to login a user when they press the enter key. In your Activity, you can detect this tag and then attempt the login:I ended up with a combination of Roberts and chirags answers:
Update: The above code would some times activate the callback twice. Instead I've opted for the following code, which I got from the Google chat clients:
I know this question is old, but I want to point out what worked for me.
I tried using the sample code from the Android Developers website (shown below), but it didn't work. So I checked the EditorInfo class, and I realized that the IME_ACTION_SEND integer value was specified as
0x00000004
.Sample code from Android Developers:
So, I added the integer value to my
res/values/integers.xml
file.Then, I edited my layout file
res/layouts/activity_home.xml
as followsAnd then, the sample code worked.
Try this, it should work for what you need: