我正在尝试在 RecyclerView 中实现 Admob 广告。我尝试了很多例子,但都失败了。我想在我的 RecyclerView 的 3 个项目之间插入一个广告,我正在使用 GridLayout 和 Admob 横幅。我想要我的应用程序视图,如下所示。任何帮助,将不胜感激。我的 RecyclerView 适配器 class ProductAdapter(private val userList: ArrayList<Model.ProductList>, private val context: Context, private val which: String) : androidx.recyclerview.widget.RecyclerView.Adapter<RecyclerView.ViewHolder>() {override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { if (holder.itemViewType == 0) { holder as MyViewHolder2 val adRequest = AdRequest.Builder().build() holder.adView.loadAd(adRequest) holder.adView.adListener = object : AdListener() { override fun onAdFailedToLoad(errorCode: Int) { Log.d("errorCode", errorCode.toString()) } } } else { holder as MyViewHolder val magazineList: Model.ProductList = userList[position] Glide.with(context).load(magazineList.featured_image) .thumbnail(0.5f) .into(holder.image) holder.title.text = magazineList.post_title holder.views.text = magazineList.count holder.date.text = magazineList.offer_valid } }}override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { if (viewType == 0) { return MyViewHolder2(LayoutInflater.from(parent.context).inflate(R.layout.ad_list_row, parent, false)) } else { return MyViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.product_list_row, parent, false)) }}override fun getItemCount(): Int { return userList.size}override fun getItemViewType(position: Int): Int { return if (position>0 && position % 3== 0) { 0 } else { 1 } }
添加回答
举报
0/150
提交
取消