Comments (4)
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:
- You create
MoPubNative
object, callregisterAdRenderer
and pass yourViewBinder
to it so thatMoPubNative
knows how to render ad view. - You call
makeRequest
to request an ad. - In
onNativeLoad
method, you receive anNativeAd
object. - Call
renderAdView
of yourNativeAd
object. It knows how to render the view because you have told it already in step 1. - Call
prepare
so that yourNativeAd
can handle click events.
from mopub-nativead-adapters.
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.
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.
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)
- Unable to load class HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mopub-nativead-adapters.