I have a ListView with some focusable components inside (mostly EditText
s). Yeah, I know this isn't exactly recommended, but in general, almost everything is working fine and the focus goes where it has to go (with a few tweaks I had to code). Anyway, my problem is that there's a weird race condition when scrolling the list with your finger and then suddenly using the trackball when the IME keyboard is being displayed. Something must go out of bounds and get recycled at which point the offsetRectBetweenParentAndChild()
method must kick in and throw the IllegalArgumentException
.
The problem is that this exception is thrown outside of any block in which I can insert a try/catch (as far as I know). So there are two valid solutions to this question, either:
- Someone knows why this exception being thrown and how to stop it from happening
- Someone knows how to put a try/catch block somewhere that will at least let my application survive. As far as I know the problem is that of focus, so it definitely shouldn't kill my application (which is what it's doing). I tried overriding the
ViewGroup
's methods but those twooffset*
methods are marked as final.
Stack trace:
08-17 18:23:09.825: ERROR/AndroidRuntime(1608): FATAL EXCEPTION: main
08-17 18:23:09.825: ERROR/AndroidRuntime(1608): java.lang.IllegalArgumentException: parameter must be a descendant of this view
08-17 18:23:09.825: ERROR/AndroidRuntime(1608): at android.view.ViewGroup.offsetRectBetweenParentAndChild(ViewGroup.java:2633)
08-17 18:23:09.825: ERROR/AndroidRuntime(1608): at android.view.ViewGroup.offsetDescendantRectToMyCoords(ViewGroup.java:2570)
08-17 18:23:09.825: ERROR/AndroidRuntime(1608): at android.view.ViewRoot.scrollToRectOrFocus(ViewRoot.java:1624)
08-17 18:23:09.825: ERROR/AndroidRuntime(1608): at android.view.ViewRoot.draw(ViewRoot.java:1357)
08-17 18:23:09.825: ERROR/AndroidRuntime(1608): at android.view.ViewRoot.performTraversals(ViewRoot.java:1258)
08-17 18:23:09.825: ERROR/AndroidRuntime(1608): at android.view.ViewRoot.handleMessage(ViewRoot.java:1859)
08-17 18:23:09.825: ERROR/AndroidRuntime(1608): at android.os.Handler.dispatchMessage(Handler.java:99)
08-17 18:23:09.825: ERROR/AndroidRuntime(1608): at android.os.Looper.loop(Looper.java:130)
08-17 18:23:09.825: ERROR/AndroidRuntime(1608): at android.app.ActivityThread.main(ActivityThread.java:3683)
08-17 18:23:09.825: ERROR/AndroidRuntime(1608): at java.lang.reflect.Method.invokeNative(Native Method)
08-17 18:23:09.825: ERROR/AndroidRuntime(1608): at java.lang.reflect.Method.invoke(Method.java:507)
08-17 18:23:09.825: ERROR/AndroidRuntime(1608): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-17 18:23:09.825: ERROR/AndroidRuntime(1608): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-17 18:23:09.825: ERROR/AndroidRuntime(1608): at dalvik.system.NativeStart.main(Native Method)
In case of Expandable List View, if your child items have edit text then you need to change the focusability before descendants for Expandable List View
I faced that problem, too, and the solution by validcat worked for me, but I had to call
getWindow().getCurrentFocus().clearFocus()
.I have the simplest but not good solution. Just extend the NestedScrollView and override onSizeChanged method, add a try catch block.
In my case, I have tow layer view, top layer is listView, bottom is NestedScrollView. The error is happend when I switch the layer. The focus be taked by ListeView item (button).
So I can't make button lose focus. Then the best solution is extends NestedScrollView.
I faced with the same problem and found out this solution - in
OnGroupCollapseListener/OnGroupExpandListener
andOnScrollListener
forExpandableListView
i clear focuse and hide forced keyboard. Also do not forget to set inmanifest
for your activitywindowSoftInputMode="adjustPan"
:I don't know exactly
OnGroupExpandListener
is needed or no, it could be useless.try this
EDIT:
See also: Better Solution
In my case it was related to
windowSoftInputMode="adjustPan"
, listView and editText on list element (header view).In order to fix that I call hide soft keyboard method before activity is finished.