Example/app/src/main/java/com/google/ads/mediation/sample/mediationsample/MainActivity.java
/**
   * Populates a {@link UnifiedNativeAdView} object with data from a given {@link UnifiedNativeAd}.
   *
   * @param nativeAd the object containing the ad's assets
   * @param adView the view to be populated
   */
Populates a  UnifiedNativeAdView object with data from a given  UnifiedNativeAd.
@param nativeAd the object containing the ad's assets
@param adView the view to be populated
Populates a UnifiedNativeAdView object with data from a given UnifiedNativeAd . @param nativeAd the object containing the ad ' s assets @param adView the view to be populated
private void populateUnifiedNativeAdView(UnifiedNativeAd nativeAd, UnifiedNativeAdView adView) {
    MediaView mediaView = adView.findViewById(R.id.ad_media);
    adView.setMediaView(mediaView);
    adView.setHeadlineView(adView.findViewById(R.id.ad_headline));
    adView.setBodyView(adView.findViewById(R.id.ad_body));
    adView.setCallToActionView(adView.findViewById(R.id.ad_call_to_action));
    adView.setIconView(adView.findViewById(R.id.ad_app_icon));
    adView.setPriceView(adView.findViewById(R.id.ad_price));
    adView.setStarRatingView(adView.findViewById(R.id.ad_stars));
    adView.setStoreView(adView.findViewById(R.id.ad_store));
    adView.setAdvertiserView(adView.findViewById(R.id.ad_advertiser));
    ((TextView) adView.getHeadlineView()).setText(nativeAd.getHeadline());
    if (nativeAd.getBody() == null) {
      adView.getBodyView().setVisibility(View.INVISIBLE);
    } else {
      adView.getBodyView().setVisibility(View.VISIBLE);
      ((TextView) adView.getBodyView()).setText(nativeAd.getBody());
    }
    if (nativeAd.getCallToAction() == null) {
      adView.getCallToActionView().setVisibility(View.INVISIBLE);
    } else {
      adView.getCallToActionView().setVisibility(View.VISIBLE);
      ((Button) adView.getCallToActionView()).setText(nativeAd.getCallToAction());
    }
    if (nativeAd.getIcon() == null) {
      adView.getIconView().setVisibility(View.GONE);
    } else {
      ((ImageView) adView.getIconView()).setImageDrawable(
          nativeAd.getIcon().getDrawable());
      adView.getIconView().setVisibility(View.VISIBLE);
    }
    if (nativeAd.getPrice() == null) {
      adView.getPriceView().setVisibility(View.INVISIBLE);
    } else {
      adView.getPriceView().setVisibility(View.VISIBLE);
      ((TextView) adView.getPriceView()).setText(nativeAd.getPrice());
    }
    if (nativeAd.getStore() == null) {
      adView.getStoreView().setVisibility(View.INVISIBLE);
    } else {
      adView.getStoreView().setVisibility(View.VISIBLE);
      ((TextView) adView.getStoreView()).setText(nativeAd.getStore());
    }
    if (nativeAd.getStarRating() == null || nativeAd.getStarRating() < 3) {
      adView.getStarRatingView().setVisibility(View.INVISIBLE);
    } else {
      ((RatingBar) adView.getStarRatingView())
          .setRating(nativeAd.getStarRating().floatValue());
      adView.getStarRatingView().setVisibility(View.VISIBLE);
    }
    if (nativeAd.getAdvertiser() == null) {
      adView.getAdvertiserView().setVisibility(View.INVISIBLE);
    } else {
      ((TextView) adView.getAdvertiserView()).setText(nativeAd.getAdvertiser());
      adView.getAdvertiserView().setVisibility(View.VISIBLE);
    }
    adView.setNativeAd(nativeAd);
  }
private void populateUnifiedNativeAdView ( UnifiedNativeAd nativeAd , UnifiedNativeAdView adView ) { MediaView mediaView = adView . findViewById ( R . id . ad_media ) ; adView . setMediaView ( mediaView ) ; adView . setHeadlineView ( adView . findViewById ( R . id . ad_headline ) ) ; adView . setBodyView ( adView . findViewById ( R . id . ad_body ) ) ; adView . setCallToActionView ( adView . findViewById ( R . id . ad_call_to_action ) ) ; adView . setIconView ( adView . findViewById ( R . id . ad_app_icon ) ) ; adView . setPriceView ( adView . findViewById ( R . id . ad_price ) ) ; adView . setStarRatingView ( adView . findViewById ( R . id . ad_stars ) ) ; adView . setStoreView ( adView . findViewById ( R . id . ad_store ) ) ; adView . setAdvertiserView ( adView . findViewById ( R . id . ad_advertiser ) ) ; ( ( TextView ) adView . getHeadlineView ( ) ) . setText ( nativeAd . getHeadline ( ) ) ; if ( nativeAd . getBody ( ) == null ) { adView . getBodyView ( ) . setVisibility ( View . INVISIBLE ) ; } else { adView . getBodyView ( ) . setVisibility ( View . VISIBLE ) ; ( ( TextView ) adView . getBodyView ( ) ) . setText ( nativeAd . getBody ( ) ) ; } if ( nativeAd . getCallToAction ( ) == null ) { adView . getCallToActionView ( ) . setVisibility ( View . INVISIBLE ) ; } else { adView . getCallToActionView ( ) . setVisibility ( View . VISIBLE ) ; ( ( Button ) adView . getCallToActionView ( ) ) . setText ( nativeAd . getCallToAction ( ) ) ; } if ( nativeAd . getIcon ( ) == null ) { adView . getIconView ( ) . setVisibility ( View . GONE ) ; } else { ( ( ImageView ) adView . getIconView ( ) ) . setImageDrawable ( nativeAd . getIcon ( ) . getDrawable ( ) ) ; adView . getIconView ( ) . setVisibility ( View . VISIBLE ) ; } if ( nativeAd . getPrice ( ) == null ) { adView . getPriceView ( ) . setVisibility ( View . INVISIBLE ) ; } else { adView . getPriceView ( ) . setVisibility ( View . VISIBLE ) ; ( ( TextView ) adView . getPriceView ( ) ) . setText ( nativeAd . getPrice ( ) ) ; } if ( nativeAd . getStore ( ) == null ) { adView . getStoreView ( ) . setVisibility ( View . INVISIBLE ) ; } else { adView . getStoreView ( ) . setVisibility ( View . VISIBLE ) ; ( ( TextView ) adView . getStoreView ( ) ) . setText ( nativeAd . getStore ( ) ) ; } if ( nativeAd . getStarRating ( ) == null || nativeAd . getStarRating ( ) < 3 ) { adView . getStarRatingView ( ) . setVisibility ( View . INVISIBLE ) ; } else { ( ( RatingBar ) adView . getStarRatingView ( ) ) . setRating ( nativeAd . getStarRating ( ) . floatValue ( ) ) ; adView . getStarRatingView ( ) . setVisibility ( View . VISIBLE ) ; } if ( nativeAd . getAdvertiser ( ) == null ) { adView . getAdvertiserView ( ) . setVisibility ( View . INVISIBLE ) ; } else { ( ( TextView ) adView . getAdvertiserView ( ) ) . setText ( nativeAd . getAdvertiser ( ) ) ; adView . getAdvertiserView ( ) . setVisibility ( View . VISIBLE ) ; } adView . setNativeAd ( nativeAd ) ; }
Populates a {@link UnifiedNativeAdView} object with data from a given {@link UnifiedNativeAd}.
Populates a { @link UnifiedNativeAdView } object with data from a given { @link UnifiedNativeAd } .
// Set the media view. Media content will be automatically populated in the media view once // adView.setNativeAd() is called. // Set other ad assets. // The headline is guaranteed to be in every UnifiedNativeAd. // These assets aren't guaranteed to be in every UnifiedNativeAd, so it's important to // check before trying to display them. // This method tells the Google Mobile Ads SDK that you have finished populating your // native ad view with this native ad. The SDK will populate the adView's MediaView // with the media content from this native ad.