I’m developping an android app , and i have an EditText and a two RadioButtons (A and B ),
what i’m trying to do is :
When RadioButton A is checked , i want to change the keyboard layout to display it with the Done button ,
When the RadioButton B is checked, i want to change the keyboard layout to display it with the Search Button .
I’ve tried to change the IMEOptions of my EditText like this , but it still doesn’t work :
NB : the keyboard is already visible, what i want to do is just modify the button Search with the button Done in each case of the two radioButtons
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(btnA.isChecked() ) {
txtSearch.setImeOptions(EditorInfo.IME_ACTION_DONE);
// txtSearch.invalidate();
}
else {
txtSearch.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
// txtSearch.invalidate();
}
}
any ideas about how to do that ??
Thanks in advance.
What Android version are you targeting? I’m unable to post a comment sorry (new account), but am currently doing up a testcase to answer your question.
EDIT: Ok, I’ve figured it out. After a bit of googling (see this issue) and coding, I found that the imeOptions appear to be cached/tied to the input method. I’m not sure if this is a bug or intentional functionality. To switch the keyboard when the user taps either radio button, first make sure the inputType is set for your EditText (
android:inputType="text"), then use the following in youronCreatemethod:Note the nulling out and re-setting of the InputType.
Finally, please be aware that many popular keyboard implementations don’t give a damn what you set the
imeOptionsto, so don’t rely on this functionality in your app. Swype for example;In conclusion (see what I did there?), not to be outdone, I’ve bundled up my test program. You can find it here: http://dl.dropbox.com/u/52276321/ChangeKeyboardTest.zip