Integrate ads

Implementation

Set the VFAdInterface to your PreviewCommentsFragment

PreviewCommentsFragment previewCommentsFragment = PreviewCommentsFragment.newInstance(articleViewModel.getStory().getContainerId(), articleMetadata, this, vfSettings);
previewCommentsFragment.setAdInterface(this);
val previewCommentsFragment = PreviewCommentsFragment.newInstance(articleViewModel.getStory().getContainerId(), articleMetadata, this, vfSettings)
previewCommentsFragment.setAdInterface(this)

Integrate Google Ads

Integrate Google Ads into your application. Make sure to initialize the Google Ads SDK. Google Ads Quick Start

@Override
public ViewGroup generateAd(int adPosition) {
    RelativeLayout adContainer = new RelativeLayout(this);
    AdView adView = new AdView(this);
    adView.setAdSize(AdSize.BANNER);
    adView.setAdUnitId("ca-app-pub-3940256099942544/6300978111");

    AdRequest adRequest = new AdRequest.Builder()
        .build();
    adView.loadAd(adRequest);

    adView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 300));
    adContainer.addView(adView);
    return adContainer;
}
fun generateAd(adPosition: Int): ViewGroup ? {
    val adContainer = RelativeLayout(this)
    val adView = AdView(this)
    adView.setAdSize(AdSize.BANNER)
    adView.adUnitId = "ca-app-pub-3940256099942544/6300978111"
    val adRequest: AdRequest = Builder()
        .build()
    adView.loadAd(adRequest)
    adView.layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 300)
    adContainer.addView(adView)
    return adContainer
}

Integrate your custom ads

@Override
public ViewGroup generateAd(int adPosition) {
        String service = Context.LAYOUT_INFLATER_SERVICE;
    LayoutInflater li = (LayoutInflater) getApplicationContext().getSystemService(service);
    RelativeLayout adLayout = (RelativeLayout) li.inflate(R.layout.row_ad, null);
    return adLayout; 
}
fun generateAd(adPosition: Int): ViewGroup ? {
    val service: String = Context.LAYOUT_INFLATER_SERVICE
    val li = getApplicationContext().getSystemService(service) as LayoutInflater
    return li.inflate(R.layout.row_ad, null) as RelativeLayout
}

What’s Next