2

There is a post about this issue. But it is not so detailed.

I am using a grid adapter (extends from ArrayAdapter) with viewholder. I wrapped it with MoPubAdAdapter. Ad shows up in gridview but when I click an item, it gives me wrong one (actually, one or two item later). I think it happens because of viewholder. The item of ad that is not on the screen at the time disappers and the positioning of items get fixed, but as soon as an ad appear on the screen the positioning is broken again.

How can I fix it? Do I have to do custom integration? If so, how can I do it? Is there any documentation about it?

I used this code for MoPub integration:

// Set up a ViewBinder and MoPubNativeAdRenderer as above.
ViewBinder viewBinder = new ViewBinder.Builder(R.layout.native_ad_layout)
        .mainImageId(R.id.native_ad_main_image)
        .iconImageId(R.id.native_ad_icon_image)
        .titleId(R.id.native_ad_title)
        .build();

// Set up the positioning behavior your ads should have.
MoPubNativeAdPositioning.MoPubServerPositioning adPositioning =
        MoPubNativeAdPositioning.serverPositioning();
MoPubNativeAdRenderer adRenderer = new MoPubNativeAdRenderer(viewBinder);

// Set up the MoPubAdAdapter
mAdAdapter = new MoPubAdAdapter(mContext, adapter, adPositioning);
mAdAdapter.registerAdRenderer(adRenderer);
loadAds();
Community
  • 1
  • 1
sembozdemir
  • 4,137
  • 3
  • 21
  • 30

1 Answers1

2

You can get the original position of your element in the initial adapter like this:

position = mAdAdapter.getOriginalPosition(position);

Check out the following article: https://github.com/mopub/mopub-android-sdk/wiki/Native-Ads-with-Recycler-View

As it states

If you register any data observers on your original Adapter, you should instead register them on the MoPubRecyclerAdapter so they will receive messages with the adjusted position of content items. If you do not do this, the positions you receive for insertion and removal messages may be inaccurate. Be sure to check isAd(position) and use MoPubRecyclerAdapter#getOriginalPosition if you need the position of the item in your local adapter.

Sasha
  • 86
  • 5