SearchAdView

public final class SearchAdView extends ViewGroup

The View to display search banner ads for use with Search Ads for Apps. The ad size and ad unit ID must be set prior to calling loadAd(DynamicHeightSearchAdRequest).

Sample code:

 public class MyActivity extends Activity {
     private SearchAdView mSearchAdView;

     @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.
         mSearchAdView = new SearchAdView(this);
         mSearchAdView.setAdSize(AdSize.SMART_BANNER);
         mSearchAdView.setAdUnitId("myAdUnitId");

         // Create an ad request.
         SearchAdRequest.Builder searchAdRequestBuilder = new SearchAdRequest.Builder();

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

         // Add the SearchAdView to the view hierarchy.
         layout.addView(mSearchAdView);

         // Start loading the ad.
         mSearchAdView.loadAd(searchAdRequestBuilder.build());

         setContentView(layout);
     }

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

         // Resume the SearchAdView.
         mSearchAdView.resume();
     }

     @Override
     public void onPause() {
         // Pause the SearchAdView.
         mSearchAdView.pause();

         super.onPause();
     }

     @Override
     public void onDestroy() {
         // Destroy the SearchAdView.
         mSearchAdView.destroy();

         super.onDestroy();
     }
 }

XML Attribute Summary

Attribute Name AdsAttrs_adSize AdsAttrs_adUnitId

Inherited Constant Summary

Inherited Field Summary

Public Constructor Summary

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

Public Method Summary

void
destroy()
Destroy the SearchAdView.
AdListener
getAdListener()
Returns the AdListener for this SearchAdView.
AdSize
getAdSize()
Returns the size of the banner ad.
String
getAdUnitId()
Returns the ad unit ID.
void
loadAd(DynamicHeightSearchAdRequest dynamicHeightSearchAdRequest)
Start loading the ad on a background thread.
void
loadAd(SearchAdRequest searchAdRequest)
Start loading the ad on a background thread.
void
pause()
Pause any extra processing associated with this SearchAdView.
void
resume()
Resume an SearchAdView after a previous call to pause().
void
setAdListener(AdListener adListener)
Sets an AdListener for this SearchAdView.
void
setAdSize(AdSize adSize)
Sets the size of the banner ad.
void
setAdUnitId(String adUnitId)
Sets the ad unit ID.

Protected Method Summary

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

Inherited Method Summary