android - Putting an AdMob native ad in a listView -
i'd use new admob native ad functionality in app. want put native ad within listview, every 20th item or in list ad. possible achieve native express ad? or have use natve advanced ad?
well @jagjit has shown right approach. write step step
1. create own custom adapter (by extending baseadapter
) shown listview items
2. create layout resource file showing native ad (design should similar custom adapter created in above step)
3. in getview
method follows (for showing ad @ 2nd position)
if (position == 1) { rowview = inflater.inflate(r.layout.native_ad_adapter, null); nativeexpressadview adview = (nativeexpressadview)rowview.findviewbyid(r.id.adview); adrequest adrequest = new adrequest.builder().build(); adview.loadad(adrequest); } else { rowview = inflater.inflate(r.layout.my_custom_list, null); textview bigtxt = (textview) rowview.findviewbyid(r.id.txt1); ... ... }
here custom adapter my_custom_list
see ads loading. there small problem, actual item of list @ position 1 not shown.
4. that, add item list before populating listview
. have used arraylist
easily. approach follows
arraylist1.add(1,"ad here"); listview1.setadapter(new myadapter(callerview.getcontext(), arraylist1.toarray(new string[arraylist1.size()])));