android - add native ads from google ad mob to recycler from api -
i have recycler view
, data api ,, need add native ads ad mob failed know how working ,, create native ad on add mob , have key dont know how add in recycler please help
this adapter
public class suggestrecycler_adapter extends recyclerview.adapter<suggestrecycler_adapter.item_holder> { private int lastposition = -1; int count = 0; private interstitialad minterstitialad; private adrequest adrequest; context context; list<resultmodel> models; recyclerview.viewholder viewholder; public suggestrecycler_adapter(context context, list<resultmodel> resultmodels) { this.context = context; this.models = resultmodels; } @override public item_holder oncreateviewholder(viewgroup parent, int viewtype) { view row = layoutinflater.from(parent.getcontext()).inflate(r.layout.suggest_items, parent, false); item_holder holder = new item_holder(row); return holder; } @targetapi(build.version_codes.jelly_bean) @override public void onbindviewholder(item_holder holder, final int position) { holder.setisrecyclable(false); holder.textview_name.settext(models.get(position).getname()); iscjk(models.get(position).getname()); log.d("araaaaa", iscjk(models.get(position).getname())); holder.isopen.settext("opened now"); animation animation = animationutils.loadanimation(context, r.anim.up_from_bottom); holder.itemview.startanimation(animation); lastposition = position; } @override public int getitemcount() { return models.size(); } public class item_holder extends recyclerview.viewholder { textview textview_name, isopen; ratingbar re_star; imageview imageview_re, image_nav; public item_holder(view itemview) { super(itemview); textview_name = (textview) itemview.findviewbyid(r.id.textview); imageview_re = (imageview) itemview.findviewbyid(r.id.imageview3); image_nav = (imageview) itemview.findviewbyid(r.id.imageview4); re_star = (ratingbar) itemview.findviewbyid(r.id.ratingbar); isopen = (textview) itemview.findviewbyid(r.id.textview2); re_star.setlayoutparams(new linearlayout.layoutparams(recyclerview.layoutparams.wrap_content, recyclerview.layoutparams.wrap_content)); } } }
first, based on requirements, decide whether use native ads express or advanced described here. native ads express, may want read user guide here.
here sample on how load nativeexpressaddview:
public class mainactivity extends appcompatactivity { private static string log_tag = "example"; nativeexpressadview madview; videocontroller mvideocontroller; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); // locate nativeexpressadview. madview = (nativeexpressadview) findviewbyid(r.id.adview); // set video options. madview.setvideooptions(new videooptions.builder() .setstartmuted(true) .build()); // videocontroller can used lifecycle events , info ad's video // asset. 1 returned getvideocontroller, if ad has no video // asset. mvideocontroller = madview.getvideocontroller(); mvideocontroller.setvideolifecyclecallbacks(new videocontroller.videolifecyclecallbacks() { @override public void onvideoend() { log.d(log_tag, "video playback finished."); super.onvideoend(); } }); // set adlistener adview, activity can take action when ad has finished // loading. madview.setadlistener(new adlistener() { @override public void onadloaded() { if (mvideocontroller.hasvideocontent()) { log.d(log_tag, "received ad contains video asset."); } else { log.d(log_tag, "received ad not contain video asset."); } } }); madview.loadad(new adrequest.builder().build()); } }
wiki
Comments
Post a Comment