Update ViewPager dynamically?

后端 未结 20 3086
时光说笑
时光说笑 2020-11-22 02:00

I can\'t update the content in ViewPager.

What is the correct usage of methods instantiateItem() and getItem() in FragmentPagerAdapter class?

I was using onl

相关标签:
20条回答
  • 2020-11-22 02:43

    Here is my implementation that incorporates the info from @Bill Phillips One gets fragment caching most of the time, except when the data has changed. Simple, and seems to work fine.

    MyFragmentStatePagerAdapter.java

    private boolean mIsUpdating = false;
    public void setIsUpdating(boolean mIsUpdating) {
            this.mIsUpdating = mIsUpdating;
        }
    
    
    @Override
    public int getItemPosition(@NonNull Object object) {
    
        if (mIsUpdating) {
            return POSITION_NONE;
        }
        else {
            return super.getItemPosition(object);
        }
    }
    

    MyActivity.java

    mAdapter.setIsUpdating(true);
    mAdapter.notifyDataSetChanged();
    mAdapter.setIsUpdating(false);
    
    0 讨论(0)
  • 2020-11-22 02:44

    Try destroyDrawingCache() on ViewPager after notifyDataSetChanged() in your code.

    0 讨论(0)
提交回复
热议问题