I found similar issue Facebook Native ads in recycler view android , but had some problems with integration with Custom Ad.
For the first I tried to describe Nativ
After several hours of headache I solved my problem.
I needed to change the constructor of RecyclerView
:
public RecyclerAdapter(List food, Context context, NativeAd nativeAd, NativeAdsManager manager) {
this.foodDataList = food;
this.context = context;
this.nativeAd = nativeAd;
this.manager = manager;
}
And implement the behavior of Native Ads in onBindViewHolder
:
AdditionalHolder new_holder = (AdditionalHolder) holder;
try {
new_holder.templateContainer.removeViewInLayout(adView);
} catch (Exception e) {
e.printStackTrace();
}
nativeAd = manager.nextNativeAd();
try {
adView = NativeAdView.render(context, nativeAd, NativeAdView.Type.HEIGHT_300);
} catch (NullPointerException e) {
e.printStackTrace();
}
new_holder.templateContainer.addView(adView);
new_holder.blank_holder.setVisibility(View.GONE);
But it hasn't solved my problem entirely (micro-lags while scrolling), but still it could be useful for someone, I hoped.