View Pager in android with View Pager indicator Click Event?

1.4k views Asked by At

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.

1

There are 1 answers

0
AudioBubble On

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.