SkillAgentSearch skills...

LoopingViewPagerDemo

A demo app for trying to implement a looping ViewPager with a page indicator

Install / Use

/learn @alphamu/LoopingViewPagerDemo
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

LoopingViewPagerDemo

A demo app for trying to implement a looping ViewPager with a page indicator. The demo shows how a ViewPager can implement infinite looping either by creating new fragments all the time, or by using FragmentStatePagerAdapter with at least 4 Fragment.

About this code

You can read all about this code and why I wrote it on my medium blog. Looping/infinite ViewPager with ViewPagerIndicator

Note: If you're willing to hack it a bit, you can probably use one or two fragments as well.

Using ViewPagerIndicator by Jake Wharton

The library adds a LoopingCirclePageIndicator and a LoopingLinePageIndicator to the ViewPagerIndicator library that is included in the project in order to implement infinite looping using ViewPagerIndicator. In order to use them, you have to implement LoopingPagerAdapter on your FragmentPagerAdapter or FragmentStatePagerAdapter which adds a getRealCount() method which is used to return the real number of pages. The getCount() method in your adpater can be set to a really large number or simply Integer.MAX_INT.

Note: If you have fewer than 4 fragments, and want to use FragmentStatePagerAdapter approach, you can probably get away with hardcoding getRealCount() to 2 or 3 and creating duplicates of all the fragments.

Looping with ViewPagerIndicator

Custom approach

The demo demostrates how one can create their own Page indictors.

Looping with Custom Page Indicator

View on GitHub
GitHub Stars65
CategoryDevelopment
Updated2mo ago
Forks20

Languages

Java

Security Score

80/100

Audited on Jan 29, 2026

No findings