Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

What does onpageselected do in android viewpager?


Asked by Scarlette Boone on Nov 29, 2021 Android



Below is the MainActivity explanation. onPageSelected: This method called every time when the ViewPager changes its page position and with that, we’re changing the ViewPagerIndicator dot icons. addPagerFragments: In this function, we’re adding the pages of ViewPager means all the Fragment.
In this manner,
When a page fills the screen, its position value is 0 . When a page is drawn just off the right side of the screen, its position value is 1. If the user scrolls halfway between pages one and two, page one has a position of -0.5 and page two has a position of 0.5.
Thereof, Similar to ViewPager ’s OnPageChangeListener.onPageScrolled (), this one’s called in real-time upon any change in scroll position (even during a fling). It gives you this nice set of info values for each page —
Furthermore,
Famous applications like WhatsApp, Snapchat uses Viewpager. Viewpager2 is an updated or enhanced version of Viewpager released by Google on 7th Feb 2009. It comes with a variety of new features.
Also Know,
While a ViewPager is often coupled with a Fragment for each page using the FragmentPagerAdapter, there are cases where the pages are better off as plain views. A good example is an image gallery, where the user can swipe between different pictures.