NativeExpressAdView

public final class NativeExpressAdView extends ViewGroup

The View to display native express ads. The ad size and ad unit ID must be set prior to calling loadAd(AdRequest). Sample code:

 public class MyActivity extends Activity {
     private NativeExpressAdView mNativeExpressAdView;

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

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

         // Create a native express ad. The ad size and ad unit ID must be set before calling
         // loadAd.
         mNativeExpressAdView = new NativeExpressAdView(this);
         mNativeExpressAdView.setAdSize(new AdSize(400, 100));
         mNativeExpressAdView.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 NativeExpressAdView to the view hierarchy.
         layout.addView(mNativeExpressAdView);

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

         setContentView(layout);
     }

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

         // Resume the NativeExpressAdView.
         mNativeExpressAdView.resume();
     }

     @Override
     public void onPause() {
         // Pause the NativeExpressAdView.
         mNativeExpressAdView.pause();

         super.onPause();
     }

     @Override
     public void onDestroy() {
         // Destroy the NativeExpressAdView.
         mNativeExpressAdView.destroy();

         super.onDestroy();
     }
 }

XML Attribute Summary

Inherited Constant Summary

Inherited Field Summary

Public Constructor Summary

NativeExpressAdView(Context context)
Construct a NativeExpressAdView from code.
NativeExpressAdView(Context context, AttributeSet attrs)
Construct a NativeExpressAdView from an XML layout.
NativeExpressAdView(Context context, AttributeSet attrs, int defStyle)
Construct a NativeExpressAdView 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.
String
getMediationAdapterClassName()
Returns the mediation adapter class name.
VideoController
getVideoController()
Return the VideoController for this ad view.
VideoOptions
getVideoOptions()
Return the VideoOptions for this ad view.
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
setVideoOptions(VideoOptions videoOptions)
Set the VideoOptions 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

XML Attributes

AdsAttrs_adSize

Related Methods

AdsAttrs_adUnitId

Related Methods

Public Constructors

public NativeExpressAdView (Context context)

Construct a NativeExpressAdView from code.

Parameters
context The Context the NativeExpressAdView is running in.

public NativeExpressAdView (Context context, AttributeSet attrs)

Construct a NativeExpressAdView from an XML layout.

public NativeExpressAdView (Context context, AttributeSet attrs, int defStyle)

Construct a NativeExpressAdView from an XML layout.

Public Methods

public void destroy ()

Destroy the ad view. This method should be called in the parent Activity's onDestroy() method. No other methods should be called on the ad view after destroy() is called.

public AdListener getAdListener ()

Returns the AdListener for this ad view.

public AdSize getAdSize ()

Returns the size of the ad. Returns null if setAdSize(AdSize) hasn't been called yet.

Related XML Attributes

public String getAdUnitId ()

Returns the ad unit ID.

Related XML Attributes

public String getMediationAdapterClassName ()

Returns the mediation adapter class name. In the case of a mediated ad response, this is the name of the class that was responsible for performing the ad request and rendering the ad. For non-mediated responses, this value will be null.

public VideoController getVideoController ()

Return the VideoController for this ad view.

public VideoOptions getVideoOptions ()

Return the VideoOptions for this ad view.

public boolean isLoading ()

Returns true if the ad is loading.

public void loadAd (AdRequest adRequest)

Starts loading the ad on a background thread.

Throws
IllegalStateException If the size of the ad or the ad unit ID have not been set.

public void pause ()

Pauses any extra processing associated with this ad view. This method should be called in the parent Activity's onPause() method.

public void resume ()

Resumes an ad view after a previous call to pause(). This method should be called in the parent Activity's onResume() method.

public void setAdListener (AdListener adListener)

Sets an AdListener for this ad view.

public void setAdSize (AdSize adSize)

Sets the size of the ad.

Related XML Attributes
Throws
IllegalStateException If the size of the ad was already set.

public void setAdUnitId (String adUnitId)

Sets the ad unit ID.

Related XML Attributes
Throws
IllegalStateException If the ad unit ID was already set.

public void setVideoOptions (VideoOptions videoOptions)

Set the VideoOptions for this ad view.

Protected Methods

protected void onLayout (boolean changed, int left, int top, int right, int bottom)

protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec)

Attribute Name
AdsAttrs_adSize
AdsAttrs_adUnitId