Untitled

                Never    
Java
       
private void LoadNativeAds(final ViewGroup adContainer)
    {
        final ShimmerLayout shrimmerView = (ShimmerLayout) LayoutInflater.from(GameApplication.this).inflate(R.layout.msc_native_ad_view, null, false);

        adContainer.removeAllViews();
        adContainer.addView(shrimmerView);
        shrimmerView.startShimmerAnimation();

        com.google.android.gms.ads.AdLoader adLoader = new com.google.android.gms.ads.AdLoader.Builder(this.getApplicationContext(), "ca-app-pub-3940256099942544/2247696110")
                .forUnifiedNativeAd(new UnifiedNativeAd.OnUnifiedNativeAdLoadedListener()
                {
                    @Override
                    public void onUnifiedNativeAdLoaded(UnifiedNativeAd unifiedNativeAd)
                    {
                        // Show the ad.
                        TextView labelTitle = shrimmerView.findViewById(R.id.native_ad_title_view);
                        labelTitle.setText(unifiedNativeAd.getHeadline());

                    }
                })
                .withAdListener(new AdListener()
                {
                    @Override
                    public void onAdFailedToLoad(int errorCode)
                    {
                        // Handle the failure by logging, altering the UI, and so on.
                        Log.d(TAG, "Native ad load fail with code: "+errorCode);
                    }
                })
                .withNativeAdOptions(new NativeAdOptions.Builder()
                        // Methods in the NativeAdOptions.Builder class can be
                        // used here to specify individual options settings.
                        .build())
                .build();
    }



private void displayUnifiedNativeAd(ViewGroup parent, UnifiedNativeAd ad) {

    // Inflate a layout and add it to the parent ViewGroup.
    LayoutInflater inflater = (LayoutInflater) parent.getContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    UnifiedNativeAdView adView = (UnifiedNativeAdView) inflater
            .inflate(R.layout.my_ad_layout, parent);

    // Locate the view that will hold the headline, set its text, and call the
    // UnifiedNativeAdView's setHeadlineView method to register it.
    TextView headlineView = adView.findViewById<TextView>(R.id.ad_headline);
    headlineView.setText(ad.getHeadline());
    adView.setHeadlineView(headlineView);

    ...
    // Repeat the above process for the other assets in the UnifiedNativeAd
    // using additional view objects (Buttons, ImageViews, etc).
    ...

    // If the app is using a MediaView, it should be
    // instantiated and passed to setMediaView. This view is a little different
    // in that the asset is populated automatically, so there's one less step.
    MediaView mediaView = (MediaView) adView.findViewById(R.id.ad_media);
    adView.setMediaView(mediaView);

    // Call the UnifiedNativeAdView's setNativeAd method to register the
    // NativeAdObject.
    adView.setNativeAd(ad);

    // Ensure that the parent view doesn't already contain an ad view.
    parent.removeAllViews();

    // Place the AdView into the parent.
    parent.addView(adView);
}

Raw Text