0

I am using the this sample code and library .This library is working fine with swipe the screen but i want when click the view pager indicator slide working for that position.

Note:

This View pager indicator click is working in android phone home page.

user3793597
  • 228
  • 1
  • 2
  • 9
  • There is already mention : If you use an OnPageChangeListener with your view pager you should set it in the indicator rather than on the pager directly : titleIndicator.setOnPageChangeListener(mPageChangeListener); – Haresh Chhelana Dec 02 '14 at 05:08
  • can u refer me sample code pls – user3793597 Dec 02 '14 at 05:17
  • There is no need for 3rd party code nor any kind of manual hacks. A TabLayout is the perfect widget to build a page-indicator. You get clicks on the page-indicator out of the box. Take a look at this answer: https://stackoverflow.com/a/44231881/1850606 – xleon May 28 '17 at 22:02

1 Answers1

0

you have to set it on view of your viewPager, like this,

public class ViewPagerAdapter extends PagerAdapter {

Context context;
String[] title;
String[] image;
LayoutInflater inflater;
ArrayList<Categories> arrayList;

Activity activity;

public ViewPagerAdapter(Context context, ArrayList<Categories> arrayList) {
    this.context = context;
    this.arrayList = arrayList;
}

@Override
public int getCount() {
    // TODO Auto-generated method stub
    return arrayList.size();
}

@Override
public boolean isViewFromObject(View view, Object object) {
    // TODO Auto-generated method stub
    return view == ((RelativeLayout) object);
}

@Override
public Object instantiateItem(ViewGroup container, final int position) {
    // TODO Auto-generated method stub

    TextView txtTitle;
    ImageView image;

    inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View itemView = inflater.inflate(R.layout.item, container, false);

    itemView.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent i = new Intent(context, ListViewActivity.class);
            Bundle b = new Bundle();
            final String id = arrayList.get(position).getId();
            b.putString("id", id);
            i.putExtras(b);
            context.startActivity(i);
        }
    });

    txtTitle = (TextView) itemView.findViewById(R.id.tvName);
    image = (ImageView) itemView.findViewById(R.id.imageView1);

    txtTitle.setText(arrayList.get(position).getTitle());
    ((ViewPager) container).addView(itemView);

    Ion.with(context).load(arrayList.get(position).getImage()).withBitmap()
            .resize(512, 512).centerCrop().intoImageView(image);

    return itemView;
}

@Override
public void destroyItem(View container, int position, Object object) {
    ((ViewPager) container).removeView((View) object);
}
}

try this... it works for me.