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 395911 04f47021f97c64a8584102d91be80ec57ca47843
parent 395910 610074e75a49d4bfb82be4c7e54a58f82e1564d7
child 395912 b7cdc8cfc61fc06eaa036beb6e06da09d4d4728f
push id1468
push userasasaki@mozilla.com
push dateMon, 05 Jun 2017 19:31:07 +0000
treeherdermozilla-release@0641fc6ee9d1 [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)) {