I would like to add or delete pages from my view pager dynamically. Is that possible?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
Yes, since ViewPager gets the child Views from a PagerAdapter, you can add new pages / delete pages on that, and call .notifyDataSetChanged() to reload it.
Yes, the code should be like this:
But there is a bug. If the current Item is 0, and to remove page 0, it will not refresh the screen instantly, I haven't found a solution for this.
This solution works well for so far:
Please note:
Item
class must contain a corresponding implementation forequals
andhashCode
methodsItemView
class must contain getter and setter for yourItem
object.Here's an alternative solution to this question. My adapter:
Code to remove and add dynamically
After the advice of Peri Hartman, it started to work after I set
null
to ViewPager adapter and put the adapter again after the views removed. Before this the page 0 doesn't showed its list contents.I am sure you have created an adapter by extending PageAdapter, so there is one method:
For detailed example for the same, just go through this example.