RecycleViewerAdapter 未完美显示 admob 插页式广告
Posted
技术标签:
【中文标题】RecycleViewerAdapter 未完美显示 admob 插页式广告【英文标题】:RecycleViewerAdapter not showing admob Interstitial ads perfectly 【发布时间】:2021-12-16 05:32:50 【问题描述】:我正在尝试将来自 admob 的插页式广告集成到我的 android 项目中。但是,它在 backPressed 时工作,而不是在 onClick 中工作。我真的对我的代码中的 admob 规则感到困惑。你能检查我的代码,并修复正在发生的错误吗?基本上我想遵循 admob 广告政策并使其完美运行。
RecycleViewerAdapter.java
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.MyViewHolder>
private Context mContext;
private List<Anime> mData ;
RequestOptions option;
private InterstitialAd interstitialAd;
public RecyclerViewAdapter(Context mContext, List<Anime> mData)
this.mContext = mContext;
this.mData = mData;
interstitialAd = new InterstitialAd(mContext.getApplicationContext());
interstitialAd.setAdUnitId(mContext.getString(R.string.admob_banner));
interstitialAd.loadAd(new AdRequest.Builder().build());
// Request option for Glide
option = new RequestOptions().centerCrop().placeholder(R.drawable.loading_shape).error(R.drawable.loading_shape);
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
View view ;
LayoutInflater inflater = LayoutInflater.from(mContext);
view = inflater.inflate(R.layout.row_items,parent,false);
final MyViewHolder viewHolder = new MyViewHolder(view) ;
viewHolder.view_container.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View v)
if (interstitialAd != null)
interstitialAd.show();
else
//do something
Intent i = new Intent(mContext, WebViewActivity.class);
view.startAnimation(AnimationUtils.loadAnimation(mContext, R.anim.clcik));
i.putExtra("action_link",mData.get(viewHolder.getAdapterPosition()).getWebsite_link());
i.putExtra("puzzle_link",mData.get(viewHolder.getAdapterPosition()).getWebsite_link());
i.putExtra("arcade_link",mData.get(viewHolder.getAdapterPosition()).getWebsite_link());
i.putExtra("adventure_link",mData.get(viewHolder.getAdapterPosition()).getWebsite_link());
i.putExtra("sports_link",mData.get(viewHolder.getAdapterPosition()).getWebsite_link());
i.putExtra("racing_link",mData.get(viewHolder.getAdapterPosition()).getWebsite_link());
i.putExtra("zombie_link",mData.get(viewHolder.getAdapterPosition()).getWebsite_link());
mContext.startActivity(i);
CustomIntent.customType(mContext,"fadein-to-fadeout");
);
return viewHolder;
@Override
public void onBindViewHolder(MyViewHolder holder, int position)
Glide.with(mContext).load(mData.get(position).getWebsite_logo()).apply(option).into(holder.img_thumbnail);
@Override
public int getItemCount()
return mData.size();
public static class MyViewHolder extends RecyclerView.ViewHolder
ImageView img_thumbnail;
LinearLayout view_container;
public MyViewHolder(View itemView)
super(itemView);
view_container = itemView.findViewById(R.id.container);
img_thumbnail = itemView.findViewById(R.id.thumbnail);
请通过编辑我的代码写一个答案,这对我和其他初学者来说会更好理解。对不起我的英语不好。
提前致谢。
【问题讨论】:
【参考方案1】:不要在适配器中加载广告...
改用接口
观看本教程:Tutorial
【讨论】:
我做不到...你能编辑我的代码并发布你的答案吗?以上是关于RecycleViewerAdapter 未完美显示 admob 插页式广告的主要内容,如果未能解决你的问题,请参考以下文章
隐式超级构造函数 Person() 未定义。必须显式调用另一个构造函数?
防止 Visual Studio 调试因明显的“未处理异常”而中断
SQLSTATE[42883]:未定义函数您可能需要添加显式类型转换