private ScheduledExecutorService scheduledExecutorService;
private void startAd() { scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(); // 当Activity显示出来后,每两秒切换一次图片显示 scheduledExecutorService.scheduleAtFixedRate(new ScrollTask(), 1, 2, TimeUnit.SECONDS); } private class ScrollTask implements Runnable { @Override public void run() { synchronized (adViewPager) { currentItem = (currentItem + 1) % imageViews.size(); mHandler.obtainMessage(0).sendToTarget(); } } }private Handler mHandler = new Handler() { public void handleMessage(android.os.Message msg) { switch (msg.what) { case 0: adViewPager.setCurrentItem(currentItem); break; default: break; } } };