12

I got following exception from one of my app user in crash logs. Unable to understand from the log trace. If anybody has some thoughts, please share.

Fatal Exception: java.lang.IllegalArgumentException parameter must be a descendant of this view raw

android.view.ViewGroup.offsetRectBetweenParentAndChild (ViewGroup.java:4563) android.view.ViewGroup.offsetDescendantRectToMyCoords (ViewGroup.java:4500) android.view.ViewGroup$ViewLocationHolder.init (ViewGroup.java:6738) android.view.ViewGroup$ViewLocationHolder.obtain (ViewGroup.java:6675) android.view.ViewGroup$ChildListForAccessibility.init (ViewGroup.java:6633) android.view.ViewGroup$ChildListForAccessibility.obtain (ViewGroup.java:6601) android.view.ViewGroup.addChildrenForAccessibility (ViewGroup.java:1703) android.view.ViewGroup.onInitializeAccessibilityNodeInfoInternal (ViewGroup.java:2530) android.view.View.onInitializeAccessibilityNodeInfo (View.java:5209) android.widget.AdapterView.onInitializeAccessibilityNodeInfo (AdapterView.java:937) android.widget.AbsListView.onInitializeAccessibilityNodeInfo (AbsListView.java:1492) android.widget.ListView.onInitializeAccessibilityNodeInfo (ListView.java:3781) android.view.View.createAccessibilityNodeInfoInternal (View.java:5170) android.view.View.createAccessibilityNodeInfo (View.java:5157)

4

4 回答 4

7

我通过添加这样的自定义侦听器来修复此错误:

protected class MyScrollListener implements OnScrollListener {

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem,
                int visibleItemCount, int totalItemCount) {
            // do nothing 
        }

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
            if (SCROLL_STATE_TOUCH_SCROLL == scrollState) {
                View currentFocus = getCurrentFocus();
                if (currentFocus != null) {
                    currentFocus.clearFocus();
                }
            }
        }

    }

然后使用您创建的侦听器:

listview.setOnScrollListener(MyScrollListener);

有关更多信息,请参阅此(代码也取自此链接):防止/捕获“IllegalArgumentException:参数必须是此视图的后代”错误

于 2014-11-05T08:02:14.727 回答
3

我尝试调用 EditText 小部件的 clearFocus() 成员,但这对我不起作用。然而,真正起作用的是调用父级的 clearChildFocus(View) 函数。这是代码:

ViewParent parent = mEditText.getParent();
parent.clearChildFocus(mEditText);
于 2015-01-17T20:23:18.927 回答
0

这对我有用。

convertView = mInflater.inflate(R.layout.row_stat_header,
                    parent, false); 

这里,parent就是getView中的ViewGroup参数。

于 2015-01-28T07:06:24.793 回答
0

当我尝试将edittext与recyclerview一起使用时,我遇到了同样的错误。我认为这同样适用于使用 listview 的 editext。

当 Viewgroup 处理视图时出现焦点不匹配时会出现问题。对我来说,解决问题的方法是将 android:windowSoftInputMode="adjustPan" 添加到相关活动的清单中。

<activity android:name=".register.RegistrationActivity"
        android:windowSoftInputMode="adjustPan"/>

希望这对某人有用。

于 2018-11-07T05:41:12.973 回答