如何在列表视图中将admob广告放入片段中

时间:2016-12-25 06:19:34

标签: android admob

我希望将listob广告放在列表视图中。我尝试了这个,但它不起作用。我怎样才能实现相同的目标。如何修改else if部分,以便在列表视图中显示横幅广告。

 @Override
            public View getView(int i, View view, ViewGroup viewGroup) {
                int type = getItemViewType(i);
                if (type == 0) {
                    if (view == null) {
                        view = new EmptyCell(mContext);
                    }
                    if (i == overscrollRow) {
                        ((EmptyCell) view).setHeight(AndroidUtilities.dp(88));
                    } else {
                        ((EmptyCell) view).setHeight(AndroidUtilities.dp(16));
                    }
                } else if (type == 1) {
                    if (view == null) {
                        view = new ShadowSectionCell(mContext);
                    }
                } else if (type == 2) {
                    if (view == null) {
                        view = new TextSettingsCell(mContext);
                    }
                    TextSettingsCell textCell = (TextSettingsCell) view;

else if (i == languageRow) {
                        textCell.setTextAndValue(LocaleController.getString("Language", R.string.Language), LocaleController.getCurrentLanguageName(), true);
                    } else if (i == contactsSortRow) {
                        String value;
                        SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
                        int sort = preferences.getInt("sortContactsBy", 0);
                        if (sort == 0) {
                            value = LocaleController.getString("Default", R.string.Default);
                        } 

                    } else if ( i== adsRow)

                    {
                        adView = new AdView(this, AdSize.SMART_BANNER, "MY_ID");
                        // Set the AdListener.
                        adView.setAdListener(this);
                        // Add the AdView to the view hierarchy. The view will have no size until the ad is loaded.
                        RelativeLayout layout = (RelativeLayout) findViewById(R.id.home_layout);
                        RelativeLayout.LayoutParams adsParams =new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
                        adsParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
                        layout.addView(adView,adsParams);
                        AdRequest adRequest = new AdRequest();

                        // Start loading the ad in the background.
                        adView.loadAd(adRequest);

     }

1 个答案:

答案 0 :(得分:0)

我建议使用原生广告。它们对于listview集成来说要好得多。此外,如果您正确设置它们,它们会提供更多有效每千次展示费用。

https://firebase.google.com/docs/admob/android/native-express

Google推荐此类广告在新闻源,表格中使用。