如何在CarouselPicker中设置onclick

时间:2018-06-18 05:45:27

标签: android

在Carousel下方的oode中,当它处于特定位置时会自动进行意图活动,但我想将其作为onclick功能自动进行

CarouselPicker carouselPicker1 = (CarouselPicker)v.findViewById( R.id.carouselPicker1 );
        List<CarouselPicker.PickerItem> itemsImages = new ArrayList<>();
        itemsImages.add(new CarouselPicker.DrawableItem(R.drawable.website_design));
        itemsImages.add(new CarouselPicker.DrawableItem(R.drawable.digital_marketing));
        itemsImages.add(new CarouselPicker.DrawableItem(R.drawable.domain_registration));
        itemsImages.add(new CarouselPicker.DrawableItem(R.drawable.graphic));
        itemsImages.add(new CarouselPicker.DrawableItem(R.drawable.mob));
        itemsImages.add(new CarouselPicker.DrawableItem(R.drawable.server));
        itemsImages.add(new CarouselPicker.DrawableItem(R.drawable.software_development));
        itemsImages.add(new CarouselPicker.DrawableItem(R.drawable.ontent));
        itemsImages.add(new CarouselPicker.DrawableItem(R.drawable.ssl));
//        CarouselPicker.CarouselViewAdapter imageAdapter = new CarouselPicker.CarouselViewAdapter(this,itemsImages,0);
        CarouselPicker.CarouselViewAdapter imageAdapter = new CarouselPicker.CarouselViewAdapter(this.getContext(),itemsImages,0);
        carouselPicker1.setAdapter(imageAdapter);        

carouselPicker1.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
                @Override
                public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

                }

                @Override
                public void onPageSelected(int position) {
                    if(position == 0){
                        startActivity(new    Intent(getActivity(), website_designing.class));
                    }
                    else if(position == 1){
                        startActivity(new Intent(getActivity(), digital_marketing.class));
                    }
                    //position of the selected item
                }

                @Override
                public void onPageScrollStateChanged(int state) {

                }
            });

0 个答案:

没有答案