how to implement on icon click listener in IconPageIndicator
Asked Answered
O

1

7

I am using IconPageIndicator from viewPagerIndicator library. when an icon is clicked in the indicator i need the the view pager to move to that page.how can i get the event click when the icon is clicked? how can a know which icon is clicked in the IconPageIndicator?

Oria answered 28/10, 2013 at 7:16 Comment(1)
+1...i m going to post my solution.@bill gatesJosphinejoss
J
10

I have read your question and test sample example.you are right It can't move when we click on icons.

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

just replace the below method

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 don't forget to clean and rebuild your project.I hope it will work.

Josphinejoss answered 28/10, 2013 at 7:59 Comment(9)
@bill gates i m glad it helped you.Josphinejoss
hey I am getting an error: android.view.InflateException: Binary XML file line #11: Error inflating class com.viewpagerindicator.IconPageIndicatorSemiskilled
@Semiskilled can you show me error log?use pastie.org also do proper cleaning of both project and viewPagerIndicator lib project.Josphinejoss
hey, i got it. I had a problem with my project build path. You saved me a day buddy! :D Thanks a lot! :)Semiskilled
@Semiskilled okey..glad it helped..:)Josphinejoss
hey i posted another question in this area. Please have a look at this. #20028218Semiskilled
I'm using Gradle to inport the library, will this method work for me?Robertson
@Tom Hart sry i don't know.Josphinejoss
@Cully Cross I m glad it helped.. :)Josphinejoss

© 2022 - 2024 — McMap. All rights reserved.