AdView

public final class AdView extends ViewGroup

The View to display banner ads. The ad size and ad unit ID must be set prior to calling loadAd(AdRequest).

Publishers using DoubleClick for Publishers or Search Ads for Apps should use PublisherAdView or SearchAdView, respectively.

Sample code:

 public class MyActivity extends Activity {
     private AdView mAdView;

     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);

         LinearLayout layout = new LinearLayout(this);
         layout.setOrientation(LinearLayout.VERTICAL);

         // Create a banner ad. The ad size and ad unit ID must be set before calling loadAd.
         mAdView = new AdView(this);
         mAdView.setAdSize(AdSize.SMART_BANNER);
         mAdView.setAdUnitId("myAdUnitId");

         // Create an ad request.
         AdRequest.Builder adRequestBuilder = new AdRequest.Builder();

         // Optionally populate the ad request builder.
         adRequestBuilder.addTestDevice(AdRequest.DEVICE_ID_EMULATOR);

         // Add the AdView to the view hierarchy.
         layout.addView(mAdView);

         // Start loading the ad.
         mAdView.loadAd(adRequestBuilder.build());

         setContentView(layout);
     }

     @Override
     public void onResume() {
         super.onResume();

         // Resume the AdView.
         mAdView.resume();
     }

     @Override
     public void onPause() {
         // Pause the AdView.
         mAdView.pause();

         super.onPause();
     }

     @Override
     public void onDestroy() {
         // Destroy the AdView.
         mAdView.destroy();

         super.onDestroy();
     }
 }

XML Attribute Summary

Attribute Name AdsAttrs_adSize AdsAttrs_adUnitId

Inherited Constant Summary

Inherited Field Summary

Public Constructor Summary

AdView(Context context)
Construct an AdView from code.
AdView(Context context, AttributeSet attrs)
Construct an AdView from an XML layout.
AdView(Context context, AttributeSet attrs, int defStyle)
Construct an AdView from an XML layout.

Public Method Summary

void
destroy()
Destroy the ad view.
AdListener
getAdListener()
Returns the AdListener for this ad view.
AdSize
getAdSize()
Returns the size of the ad.
String
getAdUnitId()
Returns the ad unit ID.
InAppPurchaseListener
getInAppPurchaseListener()
Returns the InAppPurchaseListener for this ad view.
String
getMediationAdapterClassName()
Returns the mediation adapter class name.
boolean
isLoading()
Returns true if the ad is loading.
void
loadAd(AdRequest adRequest)
Starts loading the ad on a background thread.
void
pause()
Pauses any extra processing associated with this ad view.
void
resume()
Resumes an ad view after a previous call to pause().
void
setAdListener(AdListener adListener)
Sets an AdListener for this ad view.
void
setAdSize(AdSize adSize)
Sets the size of the ad.
void
setAdUnitId(String adUnitId)
Sets the ad unit ID.
void
setInAppPurchaseListener(InAppPurchaseListener inAppPurchaseListener)
Sets an InAppPurchaseListener for this ad view.
void
setPlayStorePurchaseParams(PlayStorePurchaseListener playStorePurchaseListener, String publicKey)
Set a PlayStorePurchaseListener and app's public key for this ad view.

Protected Method Summary

void
onLayout(boolean changed, int left, int top, int right, int bottom)
void
onMeasure(int widthMeasureSpec, int heightMeasureSpec)

Inherited Method Summary