Kodeco Forums

ViewPager Tutorial: Getting Started in Kotlin

In this ViewPager tutorial for Android, you'll learn how to use a ViewPager to navigate between content pages in Kotlin.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/324-viewpager-tutorial-getting-started-in-kotlin
1 Like

Wow, this is a great tutorial Diana! This is just what I was looking for. Very clearly explained! I have a question- I have fragments that contain buttons, and I want to switch from one fragment to another by clicking on buttons (instead of swiping). So, basically, I want to disable swiping by finger and instead swipe programmatically. Would viewpagers be the best way to do this? I like the sliding animation effect they provide.

@dianap21 Do you have any feedback regarding this? Thank you - much appreciated!

1 Like

The ViewPager is a great choice as you don’t have to implement the sliding animation. You can create a custom ViewPager and disable swiping by overriding onInterceptTouchEvent
and onTouchEvent.

class CustomViewPager(context: Context, attrs: AttributeSet) : ViewPager(context, attrs) {

    override fun onInterceptTouchEvent(event: MotionEvent): Boolean {
        return false
    }
    override fun onTouchEvent(event: MotionEvent): Boolean {
        return false
    }
}

@dianap21 Thanks for the reply. I like that approach. Much appreciated :+1:

Had to sign up for an account just to say how great this tutorial is. Thanks so much!

Hi Diana, thanks for the great Tutorial! Have you come across an Android equivalent to iOS ‘Page Control’ widget that would work well with this type of page control? Thanks in advance.

1 Like

@dianap21 Can you please help with this when you get a chance? Thank you - much appreciated! :]

There are many libraries available that work with the ViewPager. Here’s one that allows you to customise the page indicators: GitHub - romandanylyk/PageIndicatorView: An page indicator for Android ViewPager.

This tutorial is more than six months old so questions are no longer supported at the moment for it. Thank you!