1、如果单单使用ViewPager出现这种错误的情况,有可能是在此处出现问题的。viewpager获取布局尽量写在此方法中,不要在外部直接new 一个组件添加到List集合中,如果传入的情况下,父容器是没法remove代码中new的组件的。
@Override
public Object instantiateItem(ViewGroup container, int position) {
// TODO Auto-generated method stub
View channelView = LayoutInflater.from(mContext).inflate(
R.layout.store_view_channel_image, container, false);
ImageView mImageView = (ImageView) channelView
.findViewById(R.id.channel_image);
mImageView.setImageResource(imageResId[position]);
container.addView(channelView);
channelView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
// Intent mIntent=new Intent(mContext,ChannelActivity.class);
// mContext.startActivity(mIntent);
}
});
return channelView;
}
2、ViewPager Fragme