How to swipe ViewPager images automatically using TimeTask

后端 未结 13 2273
天涯浪人
天涯浪人 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:42

    try this code: In MainActivity -

    int currentIndex=0; //for tracking current item 
    

    Create and set your TimerTask as per your requirement then in run() of TimerTask:

    public void run() {
        if((currentIndex+1)>imageId.length() ){
          currentIndex=0;
        }else{
          currentIndex++;
        }
        ViewPager.setCurrentItem(currentIndex);
    }
    

提交回复
热议问题