1 回答
TA贡献1811条经验 获得超6个赞
您应该按照此处的说明进行操作:
https://github.com/GoodieBag/CarouselPicker
为每个 Carousel 选择器设置监听器,然后为每个位置使用 switch-case 的特定逻辑:
carouselPicker.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
//position of the selected item
switch (position) {
case 0:
//do smth
Toast.makeText(MainActivity.this, "first item selected", Toast.LENGTH_SHORT).show();
break;
case 1:
// do smth else
Toast.makeText(MainActivity.this, "second item selected", Toast.LENGTH_SHORT).show();
break;
//case 3, etc...
}
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
添加回答
举报