lsjwzh / RecyclerViewPager

Deprecated
Apache License 2.0
3.53k stars 667 forks source link

和Fragment的结合,getItem会连续调用2次的bug,有办法取消吗 #155

Closed tushantong closed 5 years ago

tushantong commented 7 years ago
        @Override
        public Fragment getItem(int position, Fragment.SavedState savedState) {
            Fragment f = mFragmentCache.containsKey(position) ? mFragmentCache.get(position)
                    : new ShopItemFrag();
            LogUtils.e("getItem:" + position + " from cache" + mFragmentCache.containsKey
                    (position));
            if (savedState == null || f.getArguments() == null) {
                Bundle bundle = new Bundle();
                bundle.putInt("index", position);
                f.setArguments(bundle);
                LogUtils.e("setArguments:" + position);
            } else if (!mFragmentCache.containsKey(position)) {
                f.setInitialSavedState(savedState);
                LogUtils.e("setInitialSavedState:" + position);
            }
            mFragmentCache.put(position, f);
            return f;
        }

Log中可以看到同一秒(10:10:17)调用了2次getItem的方法。并初始化了2个Fragment,可以让它滑动一页只调用一次吗? `

03-24 10:10:17.104 29626-29626/com.swm.goodssale E/LogUtils: getItem:2 from cachefalse 03-24 10:10:17.107 29626-29626/com.swm.goodssale E/LogUtils: 执行ShopItemFrag{14b3a508 #0 id=0x575f4390 3} 03-24 10:10:17.388 29626-29626/com.swm.goodssale E/LogUtils: getItem:3 from cachefalse 03-24 10:10:17.392 29626-29626/com.swm.goodssale E/LogUtils: 执行ShopItemFrag{50d537e #2 id=0x29371d43 4} `