How to swipe ViewPager images automatically using TimeTask

后端 未结 13 2228
天涯浪人
天涯浪人 2020-12-25 13:54

Hi I am new in android and in my app I have a lot of images in my ArrayList that \'s why I want to swipe those images automatically for every 3 seconds with he

13条回答
  •  粉色の甜心
    2020-12-25 14:31

    Auto swipe ViewPager in Kotlin, simple and easy code.(if you have only 2 page)

    val handler = Handler()
    val update = Runnable {
           viewPager.setCurrentItem(currentPage % 2, true);
           currentPage++
          }
    var timer = Timer()// This will create a new Thread
        timer!!.schedule(object : TimerTask() {
             override fun run() {
             handler.post(update)
             }
       }, 500(DELAY_MS), 3000(PERIOD_MS))
    

提交回复
热议问题