The specified child already has a parent. You must call removeView() on the child's parent first.解决办

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

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值