Giter Site home page Giter Site logo

Comments (4)

ayltai avatar ayltai commented on September 24, 2024

Data binding variable data is a com.mopub.nativeads.ViewBinder as defined in native_ad_item.xml, and the code tries to data bind it to adView:

(holder as AdsViewHolder).bind(adView)

Therefore you got the error.

To render MoPub native ad view, you don't need any Data Binding. MoPub's ViewBinder will handle most of the rendering logic for you.

You can use the official AdapterHelper to render in RecyclerView, or use the following steps so that you can use custom adapter and ViewHolder.

The concept is like this:

  1. You create MoPubNative object, call registerAdRenderer and pass your ViewBinder to it so that MoPubNative knows how to render ad view.
  2. You call makeRequest to request an ad.
  3. In onNativeLoad method, you receive an NativeAd object.
  4. Call renderAdView of your NativeAd object. It knows how to render the view because you have told it already in step 1.
  5. Call prepare so that your NativeAd can handle click events.

from mopub-nativead-adapters.

adam-hurwitz avatar adam-hurwitz commented on September 24, 2024

Thanks @ayltai for the quick response. I've updated my code above to show that I do have the AdapterHelper named moPubAdapterHelper passed into the ContentAdapter class that is showing the existing content.

You can use the official AdapterHelper to render in RecyclerView

In what method of the existing ContentAdapter class would the passed in AdapterHelper be used to create the adView? It seems like the advVew would need to be created in onBindViewHolder...

from mopub-nativead-adapters.

ayltai avatar ayltai commented on September 24, 2024

I don't recommend using AdapterHelper in RecyclerView, because it is not intended to be used this way. You have to be aware of the ad lifecycle because you need to call AdapterHelper.getAdView() in onNativeLoad. AdapterHelper is designed to be used to show a single ad view.

You should use MoPubAdAdapter as described in Method 1 and Method 2, or do it as described in the original article you read.

from mopub-nativead-adapters.

adam-hurwitz avatar adam-hurwitz commented on September 24, 2024

I've moved forward with the MoPubRecyclerAdapter implementation for the alpha release. As a workaround for ads appearing next to each other after non ad content is dismissed, the user may refresh the RecyclerView for new content which also updates the ads.

Moving forward I will revisit this in a future release with a basic working demo app in order to create a fully customized experience with ads swiping. Until then I will mark this ticket closed. I appreciate the feedback.

from mopub-nativead-adapters.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.