Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
int currentItem = viewpager.getCurrentItem();
currentItem++;
viewpager.setCurrentItem(currentItem);
handler.sendEmptyMessageDelayed(1, 2000);
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
viewpager.setCurrentItem(10000)
viewpager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
switch (position % 4) {
case 0:
icon1.setImageResource(R.mipmap.big_dot)
icon2.setImageResource(R.mipmap.small_dot)
icon3.setImageResource(R.mipmap.small_dot)
icon4.setImageResource(R.mipmap.small_dot)
break
case 1:
icon1.setImageResource(R.mipmap.small_dot)
icon2.setImageResource(R.mipmap.big_dot)
icon3.setImageResource(R.mipmap.small_dot)
icon4.setImageResource(R.mipmap.small_dot)
break
case 2:
icon1.setImageResource(R.mipmap.small_dot)
icon2.setImageResource(R.mipmap.small_dot)
icon3.setImageResource(R.mipmap.big_dot)
icon4.setImageResource(R.mipmap.small_dot)
break
case 3:
icon1.setImageResource(R.mipmap.small_dot)
icon2.setImageResource(R.mipmap.small_dot)
icon3.setImageResource(R.mipmap.small_dot)
icon4.setImageResource(R.mipmap.big_dot)
break
}
}
@Override
public void onPageScrollStateChanged(int state) {
}
})
handler.sendEmptyMessageDelayed(1, 2000)
}