2

I want to use this library in my application: https://github.com/Devlight/InfiniteCycleViewPager

I imported and added this library in my application and I set it.
But I don't know how can I use the setOnClickListener() method for these viewPager items?

For instance, when I click on item1, go to this item: fragment

How can I do that?

3 Answers3

0

You have to do some changes in this library go through this link1 and sample of that library Where u can change for on click link2

Community
  • 1
  • 1
Bhavin Patel
  • 872
  • 13
  • 30
0

Just set a page change listener for your InfiniteCycleViewPager and it will call the method onPageSelected(int position) when click on view.

YourInfiniteCycleViewPager.addOnPageChangeListener(this);

To retrieve the right position for the InfiniteCycleViewPager you should call getRealItem() when onPageSelected called.

AMarones
  • 1,203
  • 11
  • 9
0

You have to create an adapter for your InfiniteCycleViewPager, for example YourAdapter.java which extends PagerAdapter. Then set this adapter to yourInfiniteCycleViewPager.setAdapter(mYourAdapter);

In override method: instantiateItem(ViewGroup, int), you can simply add your onClick listener and add logic to it:

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

    ....

    View view = LayoutInflater.from(mContext).inflate(R.layout.xxx_your_layout, null);

    view.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
             // TODO
             // do your code, and you can use variable 'position' here.
        }
    });
}
mag_zbc
  • 6,801
  • 14
  • 40
  • 62
bhw1899
  • 87
  • 4