轮播图
程序员文章站
2023-12-30 15:20:34
...
轮播图
Pageadapter pageadapter = new Pageadapter();
ViewPager.setAdapter(pageadapter);
ViewPager.setCurrentItem(list.size() * 10000);
ViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageSelected(int arg0) {
// TODO Auto-generated method stub
if (arg0 % list.size() == list.size() -1) {
button.setVisibility(View.VISIBLE);
}
switch (arg0 % list.size()) {
case 0:
radioGroup.check(R.id.but01);
break;
case 1:
radioGroup.check(R.id.but02);
break;
case 2:
radioGroup.check(R.id.but03);
break;
case 3:
radioGroup.check(R.id.but04);
break;
case 4:
radioGroup.check(R.id.but05);
break;
default:
break;
}
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
// TODO Auto-generated method stub
}
@Override
public void onPageScrollStateChanged(int arg0) {
// TODO Auto-generated method stub
}
});
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(MainActivity.this,second.class);
startActivity(intent);
}
});
intidata();
}
private void intidata() {
// TODO Auto-generated method stub
Timer timer = new Timer();
TimerTask timerTask = new TimerTask() {
@Override
public void run() {
// TODO Auto-generated method stub
handler.sendEmptyMessage(0);
}
};
timer.schedule(timerTask,2000 , 2000);
}
Handler handler = new Handler(){
public void handleMessage(android.os.Message msg) {
int currentItem = ViewPager.getCurrentItem();
currentItem++;
ViewPager.setCurrentItem(currentItem);
};
};