title: How to Show two Admob Native ads on same activity in android studio
body: <p>I want to use 2 Admob native ads in the same activity but with different sizes...
  I already have successfully implemented one ad. now I want to show one more native ad in the same activity. How to do it properly</p>
  <p>Admob implementation in the activity</p>
  <pre><code>private void populateUnifiedNativeAdView(UnifiedNativeAd nativeAd, UnifiedNativeAdView
              adView) {
          // Set the media view. Media content will be automatically populated in the media view once
          MediaView mediaView = adView.findViewById(R.id.ad_media);
          adView.setMediaView(mediaView);
  
          // Set other ad assets.
          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));
  
          // The headline is guaranteed to be in every UnifiedNativeAd.
          ((TextView) adView.getHeadlineView()).setText(nativeAd.getHeadline());
  
          // These assets aren't guaranteed to be in every UnifiedNativeAd, so it's important to
          // check before trying to display them.
          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) {
              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);
          }
  
          // 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.
          adView.setNativeAd(nativeAd);
  
          // Get the video controller for the ad. One will always be provided, even if the ad doesn't
          // have a video asset.
          VideoController vc = nativeAd.getVideoController();
  
          // Updates the UI to say whether or not this ad has a video asset.
          if (vc.hasVideoContent()) {
  
              // Create a new VideoLifecycleCallbacks object and pass it to the VideoController. The
              // VideoController will call methods on this object when events occur in the video
              // lifecycle.
              vc.setVideoLifecycleCallbacks(new VideoController.VideoLifecycleCallbacks() {
                  @Override
                  public void onVideoEnd() {
                      // Publishers should allow native ads to complete video playback before
                      // refreshing or replacing them with another ad in the same UI location.
  
                      super.onVideoEnd();
                  }
              });
          } else {
          }
      }
  
      /**
       * Creates a request for a new native ad based on the boolean parameters and calls the
       * corresponding &quot;populate&quot; method when one is successfully returned.
       */
      private void refreshAd() {
  
          AdLoader.Builder builder = new AdLoader.Builder(this, getString(R.string.admob_native_advance));
  
          builder.forUnifiedNativeAd(new UnifiedNativeAd.OnUnifiedNativeAdLoadedListener() {
              @Override
              public void onUnifiedNativeAdLoaded(UnifiedNativeAd unifiedNativeAd) {
                  // You must call destroy on old ads when you are done with them,
                  // otherwise you will have a memory leak.
                  if (nativeAd != null) {
                      nativeAd.destroy();
                  }
  //                nativeAd = unifiedNativeAd;
  //
  //
  //                RelativeLayout relativeLayout =
  //                        findViewById(R.id.fl_adplaceholder);
  //                UnifiedNativeAdView adView = (UnifiedNativeAdView) getLayoutInflater()
  //                        .inflate(R.layout.ad_unified, null);
  //                populateUnifiedNativeAdView(unifiedNativeAd, adView);
  //
  //
  //                relativeLayout.removeAllViews();
  //                relativeLayout.addView(adView);
  
                  NativeTemplateStyle styles = new
                          NativeTemplateStyle.Builder().build();
                  TemplateView adView = findViewById(R.id.adview);
                  adView.setVisibility(View.VISIBLE);
                  adView.setStyles(styles);
                  adView.setNativeAd(unifiedNativeAd);
              }
  
          });
  
          VideoOptions videoOptions = new VideoOptions.Builder()
                  .build();
  
          NativeAdOptions adOptions = new NativeAdOptions.Builder()
                  .setVideoOptions(videoOptions)
                  .build();
  
          builder.withNativeAdOptions(adOptions);
  
          AdLoader adLoader = builder.withAdListener(new AdListener() {
              @Override
              public void onAdFailedToLoad(int errorCode) {
                  Log.w(HELPER_TAG, &quot;onAdFailedToLoad: &quot; + errorCode);
              }
          }).build();
  
          adLoader.loadAd(new AdRequest.Builder()
                  .build());
      }
  </code></pre>
  <p>1st AdMob native ad layout (implemented successfully)</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;merge xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
      &gt;
      &lt;com.google.android.gms.ads.formats.UnifiedNativeAdView
          android:id=&quot;@+id/native_ad_view&quot;
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;120dp&quot;
          android:layout_centerInParent=&quot;true&quot;
          android:background=&quot;@color/dark_bg&quot;
          &gt;
          &lt;RelativeLayout
              android:layout_width=&quot;match_parent&quot;
              android:layout_height=&quot;match_parent&quot;
              android:layout_marginBottom=&quot;5dp&quot;
              &gt;
              &lt;ImageView
                  android:id=&quot;@+id/icon&quot;
                  android:layout_width=&quot;60dp&quot;
                  android:layout_height=&quot;60dp&quot;
                  android:layout_marginLeft=&quot;12dp&quot;
                  android:layout_marginTop=&quot;5dp&quot;
                  android:contentDescription=&quot;@null&quot; /&gt;
              &lt;TextView
                  android:id=&quot;@+id/primary&quot;
                  android:layout_width=&quot;match_parent&quot;
                  android:layout_height=&quot;wrap_content&quot;
                  android:layout_alignTop=&quot;@id/icon&quot;
                  android:layout_alignParentRight=&quot;true&quot;
                  android:layout_marginLeft=&quot;14dp&quot;
                  android:layout_marginTop=&quot;8dp&quot;
                  android:layout_marginRight=&quot;10dp&quot;
                  android:layout_toRightOf=&quot;@id/icon&quot;
                  android:lines=&quot;1&quot;
                  android:textColor=&quot;@color/white&quot;
                  android:textSize=&quot;@dimen/gnt_text_size_large&quot;
                  android:textStyle=&quot;bold&quot; /&gt;
              &lt;LinearLayout
                  android:id=&quot;@+id/second_row&quot;
                  android:layout_width=&quot;match_parent&quot;
                  android:layout_height=&quot;wrap_content&quot;
                  android:layout_below=&quot;@id/primary&quot;
                  android:layout_marginLeft=&quot;14dp&quot;
                  android:layout_marginTop=&quot;6dp&quot;
                  android:layout_marginRight=&quot;10dp&quot;
                  android:layout_toRightOf=&quot;@id/icon&quot;
                  android:orientation=&quot;horizontal&quot;&gt;
                  &lt;RatingBar
                      android:id=&quot;@+id/rating_bar&quot;
                      android:layout_width=&quot;wrap_content&quot;
                      android:layout_height=&quot;@dimen/gnt_ad_indicator_height&quot;
                      android:lines=&quot;1&quot;
                      android:numStars=&quot;0&quot;
                      android:textColor=&quot;@color/white&quot;
                      android:textSize=&quot;@dimen/gnt_text_size_small&quot; /&gt;
                  &lt;TextView
                      android:id=&quot;@+id/secondary&quot;
                      android:layout_width=&quot;match_parent&quot;
                      android:layout_height=&quot;match_parent&quot;
                      android:layout_marginStart=&quot;@dimen/gnt_no_margin&quot;
                      android:layout_marginTop=&quot;@dimen/gnt_no_margin&quot;
                      android:layout_marginEnd=&quot;@dimen/gnt_no_margin&quot;
                      android:layout_marginBottom=&quot;@dimen/gnt_no_margin&quot;
                      android:gravity=&quot;top&quot;
                      android:lines=&quot;1&quot;
                      android:textColor=&quot;@color/white&quot;
                      android:textSize=&quot;@dimen/gnt_text_size_small&quot; /&gt;
              &lt;/LinearLayout&gt;
              &lt;Button
                  android:id=&quot;@+id/cta&quot;
                  android:layout_width=&quot;250dp&quot;
                  android:layout_height=&quot;0dp&quot;
                  android:layout_below=&quot;@id/icon&quot;
                  android:layout_marginLeft=&quot;10dp&quot;
                  android:layout_marginTop=&quot;5dp&quot;
                  android:layout_marginRight=&quot;10dp&quot;
                  android:layout_marginBottom=&quot;5dp&quot;
                  android:background=&quot;@drawable/main_ad_button&quot;
                  android:lines=&quot;1&quot;
                  android:layout_alignParentBottom=&quot;true&quot;
                  android:layout_alignParentEnd=&quot;true&quot;
                  android:textColor=&quot;@color/gnt_white&quot;
                  android:layout_alignParentRight=&quot;true&quot; /&gt;
              &lt;RelativeLayout
                  android:layout_width=&quot;wrap_content&quot;
                  android:layout_height=&quot;wrap_content&quot;
                  android:background=&quot;@drawable/ad_text_background&quot;
                  &gt;
                  &lt;TextView
                      android:id=&quot;@+id/ad_notification_view&quot;
                      android:layout_width=&quot;wrap_content&quot;
                      android:layout_height=&quot;wrap_content&quot;
                      android:layout_margin=&quot;5dp&quot;
                      android:text=&quot;Ad&quot;
                      android:textColor=&quot;@color/white_color&quot;
                      android:textSize=&quot;@dimen/gnt_ad_indicator_text_size&quot;
                      android:textStyle=&quot;bold&quot; /&gt;
              &lt;/RelativeLayout&gt;
          &lt;/RelativeLayout&gt;
      &lt;/com.google.android.gms.ads.formats.UnifiedNativeAdView&gt;
  &lt;/merge&gt;
  </code></pre>
  <p>2nd AdMob layout file (needs to be implemented)</p>
  <pre><code>&lt;com.google.android.gms.ads.formats.UnifiedNativeAdView xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;wrap_content&quot;&gt;
  
      &lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:layout_gravity=&quot;center&quot;
          android:background=&quot;@color/dark_bg&quot;
          android:minHeight=&quot;50dp&quot;
          android:orientation=&quot;vertical&quot;&gt;
  
          &lt;TextView style=&quot;@style/AppTheme.AdAttribution&quot;/&gt;
  
          &lt;LinearLayout
              android:layout_width=&quot;match_parent&quot;
              android:layout_height=&quot;wrap_content&quot;
              android:orientation=&quot;vertical&quot;
              android:paddingLeft=&quot;20dp&quot;
              android:paddingRight=&quot;20dp&quot;
              android:paddingTop=&quot;0dp&quot;&gt;
  
              &lt;LinearLayout
                  android:layout_width=&quot;match_parent&quot;
                  android:layout_height=&quot;wrap_content&quot;
                  android:orientation=&quot;horizontal&quot;&gt;
  
                  &lt;ImageView
                      android:id=&quot;@+id/ad_app_icon&quot;
                      android:layout_width=&quot;40dp&quot;
                      android:layout_height=&quot;40dp&quot;
                      android:adjustViewBounds=&quot;true&quot;
                      android:paddingBottom=&quot;5dp&quot;
                      android:paddingEnd=&quot;5dp&quot;
                      android:paddingRight=&quot;5dp&quot;/&gt;
  
                  &lt;LinearLayout
                      android:layout_width=&quot;match_parent&quot;
                      android:layout_height=&quot;wrap_content&quot;
                      android:orientation=&quot;vertical&quot;&gt;
  
                      &lt;TextView
                          android:id=&quot;@+id/ad_headline&quot;
                          android:layout_width=&quot;match_parent&quot;
                          android:layout_height=&quot;wrap_content&quot;
                          android:textColor=&quot;#0000FF&quot;
                          android:textSize=&quot;12sp&quot;
                          android:textStyle=&quot;bold&quot; /&gt;
  
                      &lt;LinearLayout
                          android:layout_width=&quot;match_parent&quot;
                          android:layout_height=&quot;wrap_content&quot;&gt;
  
                          &lt;TextView
                              android:id=&quot;@+id/ad_advertiser&quot;
                              android:layout_width=&quot;wrap_content&quot;
                              android:layout_height=&quot;match_parent&quot;
                              android:gravity=&quot;bottom&quot;
                              android:textSize=&quot;13sp&quot;
                              android:textStyle=&quot;bold&quot;/&gt;
  
                          &lt;RatingBar
                              android:id=&quot;@+id/ad_stars&quot;
                              style=&quot;?android:attr/ratingBarStyleSmall&quot;
                              android:layout_width=&quot;wrap_content&quot;
                              android:layout_height=&quot;wrap_content&quot;
                              android:isIndicator=&quot;true&quot;
                              android:numStars=&quot;5&quot;
                              android:stepSize=&quot;0.5&quot; /&gt;
                      &lt;/LinearLayout&gt;
  
                  &lt;/LinearLayout&gt;
              &lt;/LinearLayout&gt;
  
              &lt;LinearLayout
                  android:layout_width=&quot;match_parent&quot;
                  android:layout_height=&quot;wrap_content&quot;
                  android:orientation=&quot;vertical&quot;&gt;
  
                  &lt;TextView
                      android:id=&quot;@+id/ad_body&quot;
                      android:layout_width=&quot;wrap_content&quot;
                      android:layout_height=&quot;wrap_content&quot;
                      android:layout_marginRight=&quot;20dp&quot;
                      android:layout_marginEnd=&quot;20dp&quot;
                      android:textSize=&quot;11sp&quot; /&gt;
  
                  &lt;com.google.android.gms.ads.formats.MediaView
                      android:id=&quot;@+id/ad_media&quot;
                      android:layout_gravity=&quot;center_horizontal&quot;
                      android:layout_width=&quot;200dp&quot;
                      android:layout_height=&quot;105dp&quot;
                      android:layout_marginTop=&quot;5dp&quot; /&gt;
  
                  &lt;LinearLayout
                      android:layout_width=&quot;match_parent&quot;
                      android:layout_height=&quot;wrap_content&quot;
                      android:layout_gravity=&quot;end&quot;
                      android:orientation=&quot;horizontal&quot;
                      android:paddingBottom=&quot;5dp&quot;
                      android:paddingTop=&quot;5dp&quot;&gt;
  
                      &lt;TextView
                          android:id=&quot;@+id/ad_price&quot;
                          android:layout_width=&quot;wrap_content&quot;
                          android:layout_height=&quot;wrap_content&quot;
                          android:paddingLeft=&quot;5dp&quot;
                          android:paddingStart=&quot;5dp&quot;
                          android:paddingRight=&quot;5dp&quot;
                          android:paddingEnd=&quot;5dp&quot;
                          android:textSize=&quot;12sp&quot; /&gt;
  
                      &lt;TextView
                          android:id=&quot;@+id/ad_store&quot;
                          android:layout_width=&quot;wrap_content&quot;
                          android:layout_height=&quot;wrap_content&quot;
                          android:paddingLeft=&quot;5dp&quot;
                          android:paddingStart=&quot;5dp&quot;
                          android:paddingRight=&quot;5dp&quot;
                          android:paddingEnd=&quot;5dp&quot;
                          android:textSize=&quot;12sp&quot; /&gt;
  
                      &lt;Button
                          android:background=&quot;@drawable/main_ad_button&quot;
                          android:id=&quot;@+id/ad_call_to_action&quot;
                          android:layout_width=&quot;match_parent&quot;
                          android:layout_height=&quot;wrap_content&quot;
                          android:gravity=&quot;center&quot;
                          android:textSize=&quot;12sp&quot; /&gt;
                  &lt;/LinearLayout&gt;
              &lt;/LinearLayout&gt;
          &lt;/LinearLayout&gt;
      &lt;/LinearLayout&gt;
  &lt;/com.google.android.gms.ads.formats.UnifiedNativeAdView&gt;
  </code></pre>