Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PageIndicator #69

Open
rajeesh7 opened this issue Jun 7, 2018 · 2 comments
Open

PageIndicator #69

rajeesh7 opened this issue Jun 7, 2018 · 2 comments

Comments

@rajeesh7
Copy link

rajeesh7 commented Jun 7, 2018

How can we add page indicator, the dot image to bottom of this viewpager ?
On page scroll these dots must indicate the position of the current item

@MohNage7
Copy link

Did you find any solution for it ?

@cj3dreams
Copy link

cj3dreams commented Aug 28, 2022

Feeling how I being more smarter year by year :D
I used that in fragment + with PageIndicatorView (https://github.com/romandanylyk/PageIndicatorView)
it works fine! These are my codes :) enjoy

class HomeFragment : Fragment() {
    private lateinit var horizontalInfiniteCycleViewPager: HorizontalInfiniteCycleViewPager
    private lateinit var dotsIndicator: PageIndicatorView

    private var previousPage = 0
    private var currentPage = -1

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?): View? {

        val view =  inflater.inflate(R.layout.fragment_home, container, false)

        horizontalInfiniteCycleViewPager = view.findViewById(R.id.homeHorizonInfCycleViewPager)
        dotsIndicator = view.findViewById(R.id.homeDotsIndicator)

        return view
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        horizontalInfiniteCycleViewPager.adapter =
            AccountsAdapter((0..2).toList(), requireContext())
        dotsIndicator.count = 3 //Static count of pages, just for testing, I used for operator "if" only 3 pages!!! manually, but u can rewrite it with dynamic count
        dotsIndicator.setAnimationType(AnimationType.WORM)
        horizontalInfiniteCycleViewPager.addOnPageChangeListener(object: ViewPager.OnPageChangeListener{
            override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
                if (previousPage<position) {
                    if (currentPage !=2 ) currentPage++ else currentPage = 0
                    dotsIndicator.selection = currentPage
                    previousPage = position
                }
                else if (previousPage>position) {
                    if (currentPage == 0) currentPage = 2 else currentPage--
                    dotsIndicator.selection = currentPage
                    previousPage = position
                }
            }override fun onPageSelected(position: Int) {}
            override fun onPageScrollStateChanged(state: Int) {} })
   }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants