From 82a23b64156209b10fd5b38b0b01d6a88d03fe51 Mon Sep 17 00:00:00 2001 From: chrischeng <357213557@qq.com> Date: Wed, 6 Jul 2016 18:31:04 +0800 Subject: [PATCH] fix addHeaderAndFooter method. --- .../cube/views/GridViewWithHeaderAndFooter.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/in/srain/cube/views/GridViewWithHeaderAndFooter.java b/src/in/srain/cube/views/GridViewWithHeaderAndFooter.java index ce997f3..8630992 100644 --- a/src/in/srain/cube/views/GridViewWithHeaderAndFooter.java +++ b/src/in/srain/cube/views/GridViewWithHeaderAndFooter.java @@ -24,7 +24,14 @@ import android.util.Log; import android.view.View; import android.view.ViewGroup; -import android.widget.*; +import android.widget.AbsListView; +import android.widget.AdapterView; +import android.widget.Filter; +import android.widget.Filterable; +import android.widget.FrameLayout; +import android.widget.GridView; +import android.widget.ListAdapter; +import android.widget.WrapperListAdapter; import java.lang.reflect.Field; import java.util.ArrayList; @@ -156,6 +163,9 @@ public void addHeaderView(View v, Object data, boolean isSelectable) { v.setLayoutParams(new FrameLayout.LayoutParams(lyp.width, lyp.height)); fl.setLayoutParams(new AbsListView.LayoutParams(lyp.width, lyp.height)); } + + if (v.getParent() != null) + ((ViewGroup) v.getParent()).removeView(v); fl.addView(v); info.view = v; info.viewContainer = fl; @@ -189,6 +199,9 @@ public void addFooterView(View v, Object data, boolean isSelectable) { v.setLayoutParams(new FrameLayout.LayoutParams(lyp.width, lyp.height)); fl.setLayoutParams(new AbsListView.LayoutParams(lyp.width, lyp.height)); } + + if (v.getParent() != null) + ((ViewGroup) v.getParent()).removeView(v); fl.addView(v); info.view = v; info.viewContainer = fl;