Onclicklistener on ImageView Not working in PagerAdapter

125 views Asked by At

So I have an imageview in my PagerAdapter. I want to set an on click listener on it to start a new activity. I've tried a bunch of solutions on here but I cannot get any of them to work. When I tap the image in the imageView nothing happens.

Heres my adapter code

class CustomPagerAdapter extends PagerAdapter {

CharSequence[] routeDetail;
TypedArray routeImageId;
Context mContext;
LayoutInflater mLayoutInflater;
//int listViewPosition;

public CustomPagerAdapter(Context context, CharSequence[] routeDetail, TypedArray routeImageId) {
    mContext = context;
    mLayoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    this.routeDetail = routeDetail;
    this.routeImageId = routeImageId;
}

@Override
public int getCount() {
    return routeDetail.length;
}

@Override
public boolean isViewFromObject(View view, Object object) {

    return  view.equals(object);
}
@Override
public Object instantiateItem(ViewGroup container, int position) {

    View itemView = mLayoutInflater.inflate(R.layout.activity_route_details, container, false);

    TextView routeText = (TextView) itemView.findViewById(R.id.routeDetailsView);
    routeText.setText(routeDetail[position]);

    final int imageId = routeImageId.getResourceId(position, 0);
    ImageView imageView = (ImageView) itemView.findViewById(R.id.routeImage);

    imageView.setImageResource(imageId);

    ///// Pass image to new activity

    imageView.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view)
        {
            //imageView = (ImageView)view;
            Intent i = new Intent(view.getContext(),FullScreenImage.class);
            i.putExtra("mImageResource", imageId);
            //i.putExtra("routeName", routeNames[listViewPosition]);
            view.getContext().startActivity(i);
        }
    });


 ///////////
    container.addView(itemView);
    return itemView;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
    container.removeView((LinearLayout) object);
}

}

Thanks for any help!

0

There are 0 answers