I found a similar problem with Facebook Native ads in the recycler android viewer , but there were some integration issues with Custom Ad.
The first time I tried to describe NativeAdsManager:
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
manager = new NativeAdsManager(getActivity(), "892769720837476_892772047503910", 5);
manager.setListener(this);
manager.loadAds();
nativeAd = new NativeAd(getActivity(), "892769720837476_892772047503910");
nativeAd.setAdListener(this);
nativeAd.loadAd();
...
}
Then I included Native adas a parameter in the constructor RecyclerAdapter:
adapter = new RecyclerAdapter(foodDataList, getActivity(), nativeAd);
In this, ClassI also implement methods AdListenerand NativeAdsManager.Listener:
@Override
public void onError(Ad ad, AdError adError) {
}
@Override
public void onAdLoaded(Ad ad) {
}
@Override
public void onAdClicked(Ad ad) {
}
@Override
public void onAdsLoaded() {
System.out.println("Loaded in fragment");
nativeAd = manager.nextNativeAd();
nativeAd.setAdListener(this);
adapter.notifyDataSetChanged();
}
@Override
public void onAdError(AdError adError) {
}
After that in the class RecyclerAdapter:
public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) {
switch (holder.getItemViewType()) {
...
case 2:
AdditionalHolder new_holder = (AdditionalHolder) holder;
adView = NativeAdView.render(context, nativeAd, NativeAdView.Type.HEIGHT_100);
new_holder.templateContainer.addView(adView);
return;
...
public class AdditionalHolder extends RecyclerView.ViewHolder {
protected LinearLayout templateContainer;
public AdditionalHolder(View view) {
super(view);
templateContainer = (LinearLayout) view.findViewById(R.id.ad_test2);
}
}
After all this, my Fragmentc RecyclerViewbecomes very "superfluous" and every time I see more and more advertising items (1 - from the beginning, 2 - after 10 points, 3 - after the next 10 and so on).
The first time I use several RecyclerView holders, and this problem is difficult.
2 Classes
https://gist.github.com/burnix/6af8196ee8acf5c8f94e - RecyclerAdapter.class
https://gist.github.com/burnix/53dc2ed7446969b78f07 - FragmentList.class
AudienceNetwork, .
!