From 358d0d329785a225449aa9c8aea7fcc2c7bec741 Mon Sep 17 00:00:00 2001 From: Daichi Hirono Date: Mon, 1 May 2017 13:33:49 +0900 Subject: [PATCH] Don't add other's child as header or footer Previously ListView#addHeaderView and ListView#addFooterView accepts a view which is other's child. The CL adds precondition check not to accept other's child and make the methods consistent with ViewGroup#addView. Bug: 37726743 Test: CtsWidgetTestCases Change-Id: Ibe11f162e9af3c153254966796349b94468b08f3 --- core/java/android/widget/ListView.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/core/java/android/widget/ListView.java b/core/java/android/widget/ListView.java index 569fe017ac860..1457d026ea39f 100644 --- a/core/java/android/widget/ListView.java +++ b/core/java/android/widget/ListView.java @@ -49,6 +49,7 @@ import android.view.accessibility.AccessibilityNodeProvider; import android.widget.RemoteViews.RemoteView; import com.android.internal.R; +import com.android.internal.util.Preconditions; import com.google.android.collect.Lists; @@ -335,6 +336,11 @@ public class ListView extends AbsListView { * @param isSelectable whether the item is selectable */ public void addHeaderView(View v, Object data, boolean isSelectable) { + Preconditions.checkState( + v.getParent() == null, + "The specified child already has a parent. " + + "You must call removeView() on the child's parent first."); + final FixedViewInfo info = new FixedViewInfo(); info.view = v; info.data = data; @@ -429,6 +435,11 @@ public class ListView extends AbsListView { * @param isSelectable true if the footer view can be selected */ public void addFooterView(View v, Object data, boolean isSelectable) { + Preconditions.checkState( + v.getParent() == null, + "The specified child already has a parent. " + + "You must call removeView() on the child's parent first."); + final FixedViewInfo info = new FixedViewInfo(); info.view = v; info.data = data;