Bug 1354973 - Remove view before add to new ViewGroup, r=sebastian. a=gchang
authormaliu <max@mxli.us>
Mon, 10 Apr 2017 11:48:59 +0800
changeset 375961 04f47021f97c
parent 375960 610074e75a49
child 375962 b7cdc8cfc61f
push id11066
push userihsiao@mozilla.com
push dateTue, 18 Apr 2017 08:21:05 +0000
treeherdermozilla-aurora@b7cdc8cfc61f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssebastian, gchang
bugs1354973
milestone54.0a2
Bug 1354973 - Remove view before add to new ViewGroup, r=sebastian. a=gchang MozReview-Commit-ID: 1Xdlbss6SVO
mobile/android/base/java/org/mozilla/gecko/home/activitystream/topsites/TopSitesPagerAdapter.java
--- a/mobile/android/base/java/org/mozilla/gecko/home/activitystream/topsites/TopSitesPagerAdapter.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/activitystream/topsites/TopSitesPagerAdapter.java
@@ -5,16 +5,17 @@
 package org.mozilla.gecko.home.activitystream.topsites;
 
 import android.content.Context;
 import android.database.Cursor;
 import android.support.v4.view.PagerAdapter;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
+import android.view.ViewParent;
 
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.home.HomePager;
 import org.mozilla.gecko.widget.RecyclerViewClickSupport;
 
 import java.util.ArrayList;
 import java.util.List;
 
@@ -63,16 +64,22 @@ public class TopSitesPagerAdapter extend
     public boolean isViewFromObject(View view, Object object) {
         return view == object;
     }
 
     @Override
     public Object instantiateItem(ViewGroup container, int position) {
         TopSitesPage page = pages.get(position);
 
+        final ViewParent viewParent = page.getParent();
+        if (viewParent != null && viewParent instanceof ViewGroup) {
+            ViewGroup viewGroup = (ViewGroup) viewParent;
+            viewGroup.removeView(page);
+        }
+
         container.addView(page);
 
         return page;
     }
 
     @Override
     public int getItemPosition(Object object) {
         if (pages.contains(object)) {