Skip to content
This repository was archived by the owner on Jul 14, 2021. It is now read-only.
This repository was archived by the owner on Jul 14, 2021. It is now read-only.

适配器动态添加广告视图报错,麻烦看下是适配器 #508

Description

@qinchangbiao

VirtualLayoutManager: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
at android.view.ViewGroup.addViewInner(ViewGroup.java:5104)
at android.view.ViewGroup.addView(ViewGroup.java:4929)
at android.view.ViewGroup.addView(ViewGroup.java:4869)
at android.view.ViewGroup.addView(ViewGroup.java:4842)
at zy.ads.engine.adapter.XSubContentAdapter.onBindViewHolder(XSubContentAdapter.java:100)
at zy.ads.engine.adapter.XSubContentAdapter.onBindViewHolder(XSubContentAdapter.java:33)

int type = getItemViewType(position);
    Log.e(TAG, "onBindViewHolder: position>>>>>" + +position + ", " + contentBeans.get(position).getTtne() + ", type:" + type);
    switch (type) {
        case TYPE_NEW://普通处理
            GlideUtils.loadImage(mContext, contentBeans.get(position).getThumbnail(), holder.imageView, R.mipmap.item_back);
            holder.name.setText(contentBeans.get(position).getTitle());
            holder.oldprice.setText(contentBeans.get(position).getReadNum() + "次阅读");
            holder.newprice.setText(String.valueOf(contentBeans.get(position).getPublishDate()));
            holder.frameLayout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(mContext, WedHItemDivActivity.class);
                    intent.putExtra(AppConstants.Item_id, contentBeans.get(position).getId());
                    mContext.startActivity(intent);
                }
            });
            break;
        case TYPE_AD:// 广告处理
            View expressAdView = contentBeans.get(position).getTtne().getExpressAdView();
            **holder.flRoot.removeAllViews();
            holder.flRoot.addView(expressAdView);//XSubContentAdapter.java:100**
            break;

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions