Facebook Native Ads in RycyclerView android

前端 未结 2 619
渐次进展
渐次进展 2021-02-06 13:58

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

2条回答
  •  耶瑟儿~
    2021-02-06 14:15

    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.

提交回复
热议问题