Android CarouselPicker when 1st item is click

2019-03-04 23:12发布

I found a library on github that has CarouselPicker com.github.Vatican-Cameos:CarouselPicker:v1.0 i added this in the dependencies and compile also in repositories maven { url 'https://jitpack.io'}

I have successfully make a CarouselPicker this is the JAVA CODE

carouselPicker = (CarouselPicker)findViewById(R.id.carouselPicker);

    List<CarouselPicker.PickerItem> itemsImage = new ArrayList<>();
    itemsImage.add(new CarouselPicker.DrawableItem(R.drawable.abc));
    itemsImage.add(new CarouselPicker.DrawableItem(R.drawable.123));
    itemsImage.add(new CarouselPicker.DrawableItem(R.drawable.colors));
    itemsImage.add(new CarouselPicker.DrawableItem(R.drawable.shapes));
    CarouselPicker.CarouselViewAdapter imageAdapter = new CarouselPicker.CarouselViewAdapter(this, itemsImage,0);
    carouselPicker.setAdapter(imageAdapter);

And by having a LinearLayout this is the XML code

<in.goodiebag.carouselpicker.CarouselPicker
    android:id="@+id/carouselPicker"
    android:layout_marginTop="50dp"
    android:layout_marginBottom="20dp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:items_visible="three"
    />

I cant find on google on what if the 1st item in the carousel picker selected like a OnClickListenerto change the intent

1条回答
神经病院院长
2楼-- · 2019-03-04 23:35

I found a library you used on this link You must use addOnPageChangeListener like this:

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
            if(position == 0){
                startActivity(new Intent(thisActivity.this, anotherActivity1.class));
            }                
            else if(position == 1){
                startActivity(new Intent(thisActivity.this, anotherActivity2.class));
            } 
            // Same conditions for another cases.
        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    });

So, your onClickListener that you want to handle the click event, is onPageSelected method.

查看更多
登录 后发表回答