Update ViewPager dynamically?

后端 未结 20 3400
时光说笑
时光说笑 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:36

    I have lived same problem and I have searched too much times. Any answer given in stackoverflow or via google was not solution for my problem. My problem was easy. I have a list, I show this list with viewpager. When I add a new element to head of the list and I refresh the viewpager nothings changed. My final solution was very easy anybody can use. When a new element added to list and want to refresh the list. Firstly set viewpager adapter to null then recreate the adapter and set i to it to viewpager.

    myVPager.setAdapter(null);
    myFragmentAdapter = new MyFragmentAdapter(getSupportFragmentManager(),newList);
    myVPager.setAdapter(myFragmentAdapter);
    

    Be sure your adapter must extend FragmentStatePagerAdapter

提交回复
热议问题