Placing a banner in the recyclerView does not generate a new position for that element (banner) but instead "mounts" it or places it in the position of the elements practically eliminating the element that is in that position.
I'm using kotlin but if the solution is in java there is no problem, I need the idea basically how to do it, the code I have is the following:
OnCreate
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val v: View = when (viewType) {
TYPE_ADS -> LayoutInflater.from(parent.context).inflate(R.layout.card_ads, parent, false)
else -> LayoutInflater.from(parent.context).inflate(R.layout.card_download, parent, false)
}
return ViewHolder(v)
}
getItemViewType
override fun getItemViewType(position: Int): Int {
return when {
position % 8 == 0 -> TYPE_ADS
else -> TYPE_CONTENT
}
}
ViewHolder
inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
fun bindItems(item: files) {
if (itemViewType == TYPE_CONTENT) {
itemView.type_file.text = item.type
itemView.img_file.setImageDrawable(item.img_file)
itemView.name_file.text = item.name_file
itemView.size_file.text = item.size_file
itemView.path_file.text = item.path_file
itemView.path_file.isSelected = true
} else {
val ads_view = itemView.layout_ads
val adview = AdView(context)
val adSize = AdSize(300, 70)
adview.adSize = adSize
adview.adUnitId = idBanner
(ads_view as RelativeLayout).addView(adview)
adview.loadAd(AdRequest.Builder().addTestDevice(idTestDevice).build())
}
}
}
}
Thanks in advance for the collaboration.