Add / Delete pages to ViewPager dynamically

前端 未结 9 1114
囚心锁ツ
囚心锁ツ 2021-01-29 23:17

I would like to add or delete pages from my view pager dynamically. Is that possible?

9条回答
  •  梦如初夏
    2021-01-29 23:53

    I am sure you have created an adapter by extending PageAdapter, so there is one method:

     @Override
     public void destroyItem(View collection, int position, Object view) {
               ((ViewPager) collection).removeView((View) view);
     }
    

    For detailed example for the same, just go through this example.

提交回复
热议问题