clockbyte / admobadapter

It wraps your Adapter to display Admob native ads and banners in a ListView/RecyclerView data set. It based on the Yahoo fetchr project https://github.com/yahoo/fetchr
Apache License 2.0
237 stars 75 forks source link

Only 3 ads are shown at in a Listview/Recyclerview #73

Closed Sahana312 closed 7 years ago

Sahana312 commented 7 years ago

I have implemented Express ads to a list view and a Recyclerview. I get only 3 ads in the list. The list keeps growing as and when we scroll i.e when we scroll to around 20 items, we fetch another set of data and add to the list. I get only and exactly 3 ads in the list. Can you please suggest where I might be going wrong?

My code is as below.

adapterWrapper = new     AdmobExpressAdapterWrapper(mContext,mContext.getString(R.string.admob_native_key)){
                            @NonNull
                            @Override
                            protected ViewGroup getAdViewWrapper(ViewGroup parent) {
                                return (ViewGroup) LayoutInflater.from(parent.getContext()).inflate(R.layout.native_express_ad_container,
                                        parent, false);
                            }

                            @Override
                            protected void recycleAdViewWrapper(@NonNull ViewGroup wrapper, @NotNull NativeExpressAdView ad) {
                                //get the view which directly will contain ad
                                ViewGroup container = (ViewGroup) wrapper.findViewById(R.id.ad_container);
//                                    *iterating through all children of the container view and remove the first occured {@link NativeExpressAdView}. It could be different with {@param ad}!!!
                                for (int i = 0; i < container.getChildCount(); i++) {
                                    View v = container.getChildAt(i);
                                    if (v instanceof NativeExpressAdView) {
                                        container.removeViewAt(i);
                                        break;
                                    }
                                }
                            }
                            @Override
                            protected void addAdViewToWrapper (@NonNull ViewGroup wrapper, @NotNull     NativeExpressAdView ad){
                                //get the view which directly will contain ad
                                ViewGroup container = (ViewGroup) wrapper.findViewById(R.id.ad_container);
//                                    *add the {@param ad} directly to the end of container
                                container.addView(ad);
                            }

                        };
                        adapterWrapper.setAdapter(twitterAdapter);
                        adapterWrapper.setNoOfDataBetweenAds(20);
Sahana312 commented 7 years ago

I had to change the setlimitAds attribute. Closing the issue