所以我在PagerAdapter中有一个imageview。我想在其上设置一个on click侦听器以启动一个新活动。我在这里尝试过一堆解决方案,但我无法让它们中的任何一个起作用。当我点击图像中的图像时,没有任何反应。
继承我的适配器代码
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);
}
}
感谢您的帮助!