Dynamic ViewPager Indicators With RecyclerView Items in Android
Modifying a RecyclerView and it items to imitate the behavior of a tablayout or ViewPager indicators
OK i know what some developers will say “why use a RecyclerViews’s items as a ViewPager’s page indicator instead of using a TabLayout or TableLayout”.
Sometimes as an Android developer you can be faced with a situation where you are required to give out as much information in a ViewPager’s page indicator as in the ViewPager’s pages itself and as you may already guess a simple title and an icon may not be enough like the TabLayout offers. Imagine that you have a ViewPager in which each page has to display a list of Dishes for a certain restaurant and that it indicators have to act like a title,have an image or logo of the restaurant, show ratings of the restaurant and above all be able to sync with the page change of each page in the ViewPager to show information for every restaurant in the ViewPager’s Adapter.
I will show you how to handle all this by using a RecyclerView Adapter with items as indicators and keeping the same sync level as if the ViewPager was actually using Tabs as page indicator.