Reputation: 427
very simply:
inputField.setImeOptions(EditorInfo.IME_ACTION_DONE);
used to make my soft keyboard show the "done" key instead of carraige return.
Since I updated my phone (Samsung Galaxy S) to gingerbread this line of code is having no effect.
Any ideas?
Upvotes: 4
Views: 6145
Reputation: 3276
I've checked inside the method TextView.setInputType
and at the end of this method, InputMethodManager restarts the keyboard. So this is the trigger to change the imeOptions, not InputType.TYPE_NULL.
private void changeInputTypeAndImeOptions(EditText fieldValue, int inputType, int imeOption) {
if (inputType == InputType.TYPE_NULL) inputType = fieldValue.getInputType();
fieldValue.setImeOptions(imeOption | EditorInfo.IME_FLAG_NO_FULLSCREEN);
//Makes the trigger for the imeOptions to change while typing!
//fieldValue.setInputType(InputType.TYPE_NULL);
fieldValue.setInputType(inputType);
InputMethodManager imm = (InputMethodManager)
mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null) imm.restartInput(fieldValue);
}
NOTE:
Setting the setInputType with same previous value, doesn't give any effect so better to restart imm (this doesn't close the kb, only refreshes the buttons).
Also fieldValue.setInputType(InputType.TYPE_NULL);
has a bad effect the return button is visible during the multiple set, that's why is commented and it should be removed. Better restart the kb with imm.
Upvotes: 1
Reputation: 2008
I have seen this problem also and I believe it occurs when you have not set an inputType
. Actually all imeOptions
properties (along with a few others) get ignored completely if the inputType
is set to EditorInfo.TYPE_NULL
(the default).
So give one of these a shot (I picked next
but you can put any type in):
XML:
android:inputType="text"
android:imeOptions="actionNext"
JAVA
text.setInputType(EditorInfo.TYPE_CLASS_TEXT);
text.setImeOptions(EditorInfo.IME_ACTION_NEXT);
And if you really want to go nuts you can use setImeActionLabel('Add', SOME_ID)
and completely configure the action key (there are xml equivalentes also).
That being said. I could be completely wrong about your individual device but I figured this is easy to test and seems to always solve my problem so I should share.
Upvotes: 9
Reputation: 3857
I have been researching the same problem. The IME (input method editor) on your device is it at fault and will not display the done button in the soft keyboard or the next button for that matter. HTC sense has its own soft keyboard and does not recognize ime directives. there are others and your samsung obviously is one. this is the first time I have ran head long into android fragmentation.
I did try setting it in XML, inflating, and creating a helper class, and a heap of other things. I was relieved to find out that it simply does not work.
So now instead of the keyboard editor completing the entry we must add a done button. I'm adding it to the end of my edit text using a relative layout to align them. Ill leave the IME code for those that have that functionality.... this is the is the only quick solution, the other being writing a entire custom soft keyboard for your app.
Upvotes: 5