简体   繁体   中英

Android CarouselPicker when 1st item is click

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 OnClickListener to change the intent

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM