在我的日志中,当前位置为相同的值调用了两次,而我的计时器几乎花费了两倍的时间。NUM_PAGES 实际上占用了我的数组列表的最大大小。
NUM_PAGES = detailsArrayList.size();
// Auto start of viewpager
final Handler handler = new Handler();
final Runnable Update = new Runnable() {
public void run() {
if (currentPage == NUM_PAGES) {
currentPage = 0;
}
Log.d(TAG, "Current Page: " + currentPage);
mPager.setCurrentItem(currentPage++, false);
}
};
final Timer swipeTimer = new Timer();
swipeTimer.schedule(new TimerTask() {
@Override
public void run() {
handler.post(Update);
}
}, 5000, 5000);
// Pager listener over indicator
indicator.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageSelected(int position) {
currentPage = position;
}
@Override
public void onPageScrolled(int pos, float arg1, int arg2) {
}
@Override
public void onPageScrollStateChanged(int pos) {
}
});