gpt4 book ai didi

android - 如何在 RecyclerView 中实现 Admob Native 广告?

转载 作者:行者123 更新时间:2023-11-30 00:20:05 24 4
gpt4 key购买 nike

我尝试按照 google 的教程进行操作,但效果不佳。我的 RecyclerViewAdapter 有错误。

错误如下RecyclerViewAdapter。 (在第 9 行评论)

@Override
public void onBindViewHolder(final RecyclerViewHolder holder, final int position) {

int viewType = getItemViewType(position);

switch (viewType){

case AD_VIEW_TYPE:
NativeExpressAdViewHolder nativeExpressHolder = (NativeExpressAdViewHolder)holder;
NativeExpressAdView adView = (NativeExpressAdView)arrayList.get(Position); //Inconvertible types; cannot cast 'app.modals.cardSetterGetter' to 'com.google.android.gms.ads.NativeExpressAdView

ViewGroup adCardView = (ViewGroup)nativeExpressHolder.itemView;
adCardView.removeAllViews();

if(adView.getParent() != null){
((ViewGroup)adView.getParent()).removeView(adView);
}

adCardView.addView(adView);
break;

case MENU_ITEM_VIEW_TYPE:

default:
String card_image;
CardSetterGetter cardSetterGetter;
cardSetterGetter = arrayList.get(position);

card_image = constants.SERVERIP.concat(cardSetterGetter.getImageurl());
holder.cardSetterGetter = cardSetterGetter;
holder.title.setText(cardSetterGetter.getImagetitle()); //set title

cardSetterGetter.getTag();

PointF focusPoint = new PointF(0.5f, 0f);
// your app populates the focus point

holder.image // set image
.getHierarchy()
.setActualImageFocusPoint(focusPoint);
holder.image.setImageURI(Uri.parse(card_image));
}

}

最佳答案

  1. 您不应将 View 添加到 listItems . listItems包含项目,而不是 View 。

  2. NativeExpressAdViewHolder应该扩展 RecyclerViewHolder .

  3. holder.getPosition()是一个位置,而不是一个 adView。它不能转换为 NativeExpressAdView .

  4. 如果您仍想在项目列表中保留 adView,您应该更改项目列表的类型,如示例中所述。 private final List<Object> mRecyclerViewItems;

不是List<app.appname.CardSetterGetter>

关于android - 如何在 RecyclerView 中实现 Admob Native 广告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46477547/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com