sayyam/carouselview

OnClickEvent for individual images in the carousel?

MoeHamoud opened this issue · 1 comments

Am I overlooking something or is this possible after all?

Nevermind, figured it out.

For anyone interested:

      List<String> images = new ArrayList<>();
        images.add("https://pbs.twimg.com/profile_images/602729491916435458/hSu0UjMC.jpg");
        images.add("https://i.ytimg.com/vi/abVsdp3i34k/maxresdefault.jpg");
        images.add("https://s-media-cache-ak0.pinimg.com/236x/06/48/16/064816e27e16940a64fca43c3e16cbff.jpg");

        carouselView.setPageCount(images.size());

        carouselView.setImageListener(new ImageListener() {
            @Override
            public void setImageForPosition(final int position, ImageView imageView) {
                Glide.with(getContext())
                        .load(images.get(position))
                        .centerCrop()
                        .placeholder(R.drawable.placeholder_image)
                        .into(imageView);

                // Handle OnClick
                imageView.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        String imageUrl = images.get(position);
                        System.out.println("ImageView clicked! " + imageUrl); // outputs the imageUrl registered
                    }
                });
            }
        });