Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setItemClickListener #14

Open
TokenYc opened this issue Jul 19, 2018 · 2 comments
Open

setItemClickListener #14

TokenYc opened this issue Jul 19, 2018 · 2 comments

Comments

@TokenYc
Copy link

TokenYc commented Jul 19, 2018

How to setItemClickListener?I set OnClickListener to the ItemView.The current selected one can receive events but the others can not receive events.

code like this

        public Object instantiateItem(@NonNull ViewGroup container, final int position) {
            View view = LayoutInflater.from(SwitchWheelActivity.this).inflate(
                    R.layout.item_text, container, false);
            view.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    
                }
            });
            TextView textView = view.findViewById(R.id.tv_type);
            textView.setText(titles[position]);
            container.addView(view);
            return view;
        }
@davidhowe
Copy link

You can extract the local views from the adapter and assign onClickListeners to each.
I needed to set click events on each views to transition the pager to the relevant view, so I did this:

View[] localViews = adapter.getLocalViews(); for(int k=0; k<localViews.length; k++) { int finalK = k; localViews[k].setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { carousel_image_video_selector.setCurrentItem(finalK); } }); }

@CWrecker
Copy link

ok, so I have a whole buch of images in a carousel, but how do I add click functionality to them.
I've been asking about it here (you can see my code here too):

Stackoverflow

And when the specific item is in the middle, the function is called. I don't want this. I want it to call when I click on the image, not when it is in the middle of the carousel. and ideas?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants