Giter Site home page Giter Site logo

Comments (7)

zhaoxuyan avatar zhaoxuyan commented on July 30, 2024

the same question..please help

from viewpagercards.

rubensousa avatar rubensousa commented on July 30, 2024

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.

from viewpagercards.

antix995 avatar antix995 commented on July 30, 2024

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

Where are we creating "public Object instantiateItem for example?

from viewpagercards.

rubensousa avatar rubensousa commented on July 30, 2024

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.

from viewpagercards.

antix995 avatar antix995 commented on July 30, 2024

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

from viewpagercards.

yousofkakhki avatar yousofkakhki commented on July 30, 2024

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

from viewpagercards.

RahgoshafanGroup avatar RahgoshafanGroup commented on July 30, 2024

from viewpagercards.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.