2016-12-25 94 views
0

我想要在列表視圖中放置一個片段中的admob廣告。我嘗試過,但沒有工作。我該如何執行相同的操作。如何修改else if部分以便在列表視圖中顯示橫幅廣告。如何在一個片段中的列表視圖中放置admob廣告

@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); 

    } 

回答

相關問題