错误日志为:
java.lang.IllegalArgumentException: parameter must be a descendant of this view at android.view.ViewGroup.offsetRectBetweenParentAndChild(ViewGroup.java:6028) at android.view.ViewGroup.offsetDescendantRectToMyCoords(ViewGroup.java:5957) at android.view.ViewGroup$ViewLocationHolder.init(ViewGroup.java:8527) at android.view.ViewGroup$ViewLocationHolder.obtain(ViewGroup.java:8461) at android.view.ViewGroup$ChildListForAccessibility.init(ViewGroup.java:8396) at android.view.ViewGroup$ChildListForAccessibility.obtain(ViewGroup.java:8368) at android.view.ViewGroup.addChildrenForAccessibility(ViewGroup.java:2318) at android.view.ViewGroup.onInitializeAccessibilityNodeInfoInternal(ViewGroup.java:3563) at android.widget.AdapterView.onInitializeAccessibilityNodeInfoInternal(AdapterView.java:999) at android.widget.AbsListView.onInitializeAccessibilityNodeInfoInternal(AbsListView.java:1571) at android.widget.ListView.onInitializeAccessibilityNodeInfoInternal(ListView.java:4135) at android.view.View.onInitializeAccessibilityNodeInfo(View.java:7345) at android.view.View.createAccessibilityNodeInfoInternal(View.java:7304) at android.view.View.createAccessibilityNodeInfo(View.java:7289) at android.view.accessibility.AccessibilityRecord.setSource(AccessibilityRecord.java:146) at android.view.accessibility.AccessibilityRecord.setSource(AccessibilityRecord.java:119) at android.view.View.onInitializeAccessibilityEventInternal(View.java:7241) at android.widget.AdapterView.onInitializeAccessibilityEventInternal(AdapterView.java:1010) at android.view.View.onInitializeAccessibilityEvent(View.java:7229) at android.view.View.sendAccessibilityEventUncheckedInternal(View.java:7091) at android.view.View.sendAccessibilityEventUnchecked(View.java:7076) at android.view.View.sendAccessibilityEventInternal(View.java:7053) at android.widget.AbsListView.sendAccessibilityEventInternal(AbsListView.java:1560) at android.view.View.sendAccessibilityEvent(View.java:7020) at android.view.View$SendViewScrolledAccessibilityEvent.run(View.java:25909) at android.os.Handler.handleCallback(Handler.java:808) at android.os.Handler.dispatchMessage(Handler.java:101) at android.os.Looper.loop(Looper.java:166) at android.app.ActivityThread.main(ActivityThread.java:7529) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)
大意为:把一个viewA 作为ListViewA和ListViewB的headerView,当在ListViewB中操作viewA时,就会报这个错误,解决方案是:为每一个ListView单独添加只属于本身的View,即将:
RelativeLayout listViewHeader = (RelativeLayout) inflater.inflate(R.layout.listviewheader, listViewA, false);
listViewA.addHeaderView(listViewHeader);
listViewB.addHeaderView(listViewHeader);
改为:
RelativeLayout listViewHeaderA = (RelativeLayout) inflater.inflate(R.layout.listviewheader, listViewA, false);
RelativeLayout listViewHeaderB = (RelativeLayout) inflater.inflate(R.layout.listviewheader, listViewB, false);
listViewA.addHeaderView(listViewHeaderA);
listViewB.addHeaderView(listViewHeaderB);