fbsamples / audience-network

Open source projects to demonstrate SDK and sample code usages and integration, and to collaborate and support peers in this community.
https://developers.facebook.com/docs/audience-network
Other
319 stars 370 forks source link

Change index of native ad #137

Closed ElyteLabs closed 3 years ago

ElyteLabs commented 3 years ago

I am following the example to load native ads in recyclerview . I want to show ads after every 7 items it is working fine but the problem I am facing is that I can't remove the ad from 0th position. It is always first item in recyclerview . I want the ads to show from 7th item . How do I change its index

Faboor commented 3 years ago

In our sample we use the method NativeAdRecyclerAdapter.getItemViewType(int position) to decide whether we want to show an ad or not. If you are using our sample adapter, you can change the logic in this method to something like:

  @Override
  public int getItemViewType(int position) {
    return (position > 0 && position % AD_DISPLAY_FREQUENCY == 0) ? AD_TYPE : POST_TYPE;
  }

or customise it's logic entirely to suit your needs.