android viewpager change adapter

后端 未结 4 2045
花落未央
花落未央 2021-02-02 14:46

I\'m developing an app with a ViewPager for lateral scrolling tables, sometimes i need to change the adapter to load a different set of tables. I\'ve tried to do the following:<

4条回答
  •  伪装坚强ぢ
    2021-02-02 15:36

    You need to override public int getItemPosition (Object object) in pager adapter. For every element in the viewpager, you need to return POSITION_UNCHANGED (if it is still in the pager) or POSITION_NONE (if it was removed). Otherwise the view pager won't know something has changed. I wouldn't recommend setting a new adapter, just clearing out the data in the old one.

提交回复
热议问题