为什么adView每次在ListView中可见时都会刷新?

时间:2018-10-28 14:55:01

标签: android android-studio listview admob adview

我有一个问题:为什么adView每次在ListView中可见时都会刷新?我猜想,这与admob规则完全不符。我希望你能帮助我。

我的代码(适配器):

            @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
            if(position == (getCount() / 4) || position == (getCount() / 4 * 3)) {
                convertView = getLayoutInflater().inflate(R.layout.listview_ad_layout, null);
                NativeExpressAdView mAdView = new NativeExpressAdView(MainActivity.mainActivity.getApplicationContext());
                if(position == (getCount() / 4)) { //first banner
                    mAdView.setAdSize(AdSize.BANNER);
                    mAdView.setAdUnitId("ca-app-pub-3940256099942544/6300978111"); //testId
                }else if(position == (getCount() / 4 * 3)) { //second banner
                    mAdView.setAdSize(AdSize.BANNER);
                    mAdView.setAdUnitId("ca-app-pub-3940256099942544/6300978111"); //testId
                }
                FrameLayout frameLayout = (FrameLayout) convertView.findViewById(R.id.adViewListview);
                frameLayout.addView(mAdView);
                AdRequest adRequest = new AdRequest.Builder().build();
                mAdView.loadAd(adRequest);
            }else{
                // other code
            }
            return convertView;
        }

0 个答案:

没有答案