How to implement a click listener on an icon in IconPageIndicator

I am using the IconPageIndicator from the viewPagerIndicator library. when I click the icon in the indicator, I need the presentation pager to move to this page. How can I get an event by clicking on an icon? how to find out which icon was clicked in IconPageIndicator ?

+7
android viewpagerindicator
source share
1 answer

I read your question and example example. You're right. He cannot move when we click on the icons.

so you need to edit the library project ---> IconPageIndicator.java

just replace the method below

 public void notifyDataSetChanged() { mIconsLayout.removeAllViews(); IconPagerAdapter iconAdapter = (IconPagerAdapter) mViewPager.getAdapter(); int count = iconAdapter.getCount(); for (int i = 0; i < count; i++) { ImageView view = new ImageView(getContext(), null, R.attr.vpiIconPageIndicatorStyle); view.setImageResource(iconAdapter.getIconResId(i)); view.setTag(""+i); view.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { int viewPosition = Integer.parseInt(v.getTag().toString()); mViewPager.setCurrentItem(viewPosition); } }); mIconsLayout.addView(view); } if (mSelectedIndex > count) { mSelectedIndex = count - 1; } setCurrentItem(mSelectedIndex); requestLayout(); } 

clean the library project and rebuild it. Also remember to clean and rebuild your project. I hope it works.

+10
source share

All Articles