How to get EditText, IME Action, textMultiLine, to work for JellyBean
Asked Answered
K

5

6

I've run into quite the conundrum and am failing to find a solution. Apparently JellyBean changes how IME actions are handled. I've found many websites offering a solution which indeed works but only for single lined EditTexts. Example: Stackoverflow: onEditorAction

My EditText widgets worked perfectly until JellyBean. It would properly word-wrap until the user hit the "Done" (return) key. Then it'd catch the event with the OnEditorActionListener and process accordingly. I've tried multiple variations of changing the settings with the following XML attributes to no avail:

  • singleLined
  • scrollHorizontally
  • inputType
  • imeOptions
  • lines

I could only get word-wrapping with no onEditorAction event fired or no word-wrapping with the onEditorAction event firing. How can I get word-wrapping and handle the softkeyboard enter key at the same time for JellyBean?

Update 1: Including requested code. Note this is how it stands now which works for all platforms except JellyBean. As I said earlier, tried multiple different XML settings to no avail.

Update 2: Managed to get a hold of an Asus Transformer running JellyBean 4.1.1. Works fine. So perhaps this is a device specific bug? My other JellyBean device is a Nexus 7 running 4.1.2. Can anyone verify this with other devices?

Code:

private class OnMyEditorActionListener implements OnEditorActionListener {
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        if (actionId == EditorInfo.IME_ACTION_GO) {
            doSomething();
            return true;
        }
        return false;
    }
}
<EditText
    android:id="@+id/editbox_box_et"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@null"
    android:gravity="top|center_horizontal"
    android:imeOptions="actionGo"
    android:inputType="textMultiLine|textNoSuggestions"
    android:padding="@dimen/spacing_half"
    android:textSize="24sp" >
</EditText>
Kandicekandinsky answered 5/11, 2012 at 19:46 Comment(2)
It may help to show code and what your build target is.Alcoholometer
Code included. Target is JellyBean.Kandicekandinsky
K
1

After a lot of testing, I've determined this is a bug specific to the Nexus 7 and there is nothing code wise I can do to work around it. Interestingly, if I download a different keyboard from Google Play, then the code actually works!

Kandicekandinsky answered 16/11, 2012 at 12:59 Comment(1)
On an additional note: Seems like soft-keyboard creators are not forced to support ime option by definition. That would explain why they don't show up on some keyboards. So I guess relying on those as an integral part of the app is not a good idea.Heaps
N
5

Provide an ID by yourself to your submit/go button

In activity:

private class OnMyEditorActionListener implements OnEditorActionListener {
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        if (actionId == R.id.your_new_ID || actionId == EditorInfo.IME_Null) {
            doSomething();
            return true;
        }
        return false;
    }
}

In xml:

<EditText
    android:id="@+id/editbox_box_et"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@null"
    android:gravity="top|center_horizontal"
    android:inputType="textMultiLine|textNoSuggestions"
    android:padding="@dimen/spacing_half"
    android:textSize="24sp" 
    android:imeActionId="@+id/your_new_ID"
    android:imeActionLabel="Go"> </EditText>
Newsdealer answered 7/8, 2014 at 9:44 Comment(2)
This was actually quite usefull, solved my problem. I would give you a cookie if i could.Dumuzi
This seems to work fine. The multiline functionality is preserved and it's now up to me to label and handle the enter key however I want. Lightweight and effective. There are some more fixes related to the same issue in #5014719Kneepad
T
2

try the following:

android:inputType="text"
android:imeOptions="actionNone"

and also check out with different options for word-wrapping in imeOptions xml file

Tallulah answered 15/11, 2012 at 11:57 Comment(1)
Negative. Text, actionNone does not work. I've already tried multiple variations with text, textMultiLine, and textImeMultiLine. Along with actionNone, actionGo, actionDone, and flagNoEnterAction. Nothing seems to work on the Nexus 7Kandicekandinsky
K
1

After a lot of testing, I've determined this is a bug specific to the Nexus 7 and there is nothing code wise I can do to work around it. Interestingly, if I download a different keyboard from Google Play, then the code actually works!

Kandicekandinsky answered 16/11, 2012 at 12:59 Comment(1)
On an additional note: Seems like soft-keyboard creators are not forced to support ime option by definition. That would explain why they don't show up on some keyboards. So I guess relying on those as an integral part of the app is not a good idea.Heaps
B
0

Try adding attribute android:imeActionId with integer value (2 for actionGo). http://developer.android.com/reference/android/widget/TextView.html#attr_android:imeOptions

Bairn answered 12/11, 2012 at 5:29 Comment(0)
L
0

I had issue getting the event triggered for Jelly Bean 4.1.2. Adding input type helped me.

android:imeOptions="actionGo"
android:inputType="text"
Lave answered 12/11, 2012 at 22:36 Comment(1)
That doesn't allow word-wrapping.Kandicekandinsky

© 2022 - 2024 — McMap. All rights reserved.