Today a new request for ViewPager, will set ViewPager auto play, in last code is user Handler, but I want a new way to finish it.
private void autoPlay(ViewPager viewPager) {
viewPager.postDelayed(new Runnable() {
@Override
public void run() {
try {
if (adapter != null && viewPager.getAdapter().getCount() > 0) {
int position = currentCount % adapter.getCount();
currentCount++;
viewPager.setCurrentItem(position);
autoPlay(viewPager);
}
} catch (Exception e) {
Log.e(TAG, "auto scroll pager error.", e);
}
}
}, 3000);
}
So I do like that , user recursion is very simple and fast. That is.
评论
发表评论