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

How do add button click for each card view ? #20

Open
RahgoshafanGroup opened this issue Nov 17, 2017 · 7 comments
Open

How do add button click for each card view ? #20

RahgoshafanGroup opened this issue Nov 17, 2017 · 7 comments

Comments

@RahgoshafanGroup
Copy link

RahgoshafanGroup commented Nov 17, 2017

Hi, i use this ... Great !
but how to add onclick listener for each card view !?
i need go to another activity when click on each card view button !
thanks

@zhaoxuyan
Copy link

the same question..please help

@rubensousa
Copy link
Owner

Set an OnClickListener on:

@Override
public Object instantiateItem(ViewGroup container, int position)

And then store the current object as a tag inside that view.
In the OnClick(View view), retrieve the object from that tag.

@antix995
Copy link

That reply doesn't seem wildly helpful if i'm honest.

Where are we creating "public Object instantiateItem for example?

@rubensousa
Copy link
Owner

Check the sample's code. The instantiateItem is called by the PagerAdapter. I'll update the sample to reflect this use case when I have time.

@antix995
Copy link

Any chance you could elaborate more on that? I've tried doing what you say but I'm afraid that it seems to be beyond my skills. What would this code manifest as?

I really appreciate that help

@yousofkakhki
Copy link

yousofkakhki commented May 9, 2018

Hi there
here you go:
` @nonnull
@OverRide
public Object instantiateItem(@nonnull ViewGroup container, final int position) {

    View view = LayoutInflater.from(container.getContext())
            .inflate(R.layout.adapter, container, false);
    container.addView(view);
    bind(mData.get(position), view);
    CardView cardView = (CardView) view.findViewById(R.id.cardView);
    View.OnClickListener onClickListener = null;
    switch (position) {
        case 0:

            onClickListener = new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                  something();

                }
            };
          
            break;
        case 1:

            onClickListener = new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                  somethingElse();
                }
            };

     
            break;

        
    }

    cardView.setOnClickListener(onClickListener);


    if (mBaseElevation == 0) {
        mBaseElevation = cardView.getCardElevation();
    }

    cardView.setMaxCardElevation(mBaseElevation * MAX_ELEVATION_FACTOR);
    mViews.set(position, cardView);
    return view;
}`

thanks ruben for his great work. appreciate it

@RahgoshafanGroup
Copy link
Author

RahgoshafanGroup commented May 12, 2018 via email

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

No branches or pull requests

5 participants