android - Adding multiple AdViews onto a ListView -
I want to create a news app (Google SDK) with ads in the ListView. I do not know how many ads are, because I got the content from the rest of the API. There is also a separate AdUnitID in each ad.
I have already tried this solution:
- On Android I can only set ViewTypeCount once (not in iOS, where we can do this Dynamically). So I tried to set ViewTypeCount to a higher number (manual according to the code) and I was typing a new view for each ad. This is the best solution, but requires very high CPU usage, when almost no ads are loaded.
- Tried to use only a single view-type for AdView, but then I can not change AdUnitID, because a limit on AdView, this parameter can only be set once. So I need to create a new view for each ad.
Do anyone have any solutions to how I can solve this issue?
Thank you
What I usually do is a base class list is itam ListItemInterface applies when I have all my ListView items (both in your case news and your ad cover), expand ListItem. Items then generate their own ideas on the fly.
As soon as you receive news and advertisements from your REST, create new news or ad objects, add them to your list and call the adapter. NotifyDataSetChanged ().
If you think this solution will work for you, but there are more questions, then I would be happy to explain (I'm using something similar for some of my feed-based apps) .
implements public intangible class inventory ListViewInterface {} Public Interface ListItemInterface {seeView View (Reference Reference, LayoutInflater Inflator); } Public category ListItemAdapter BaseAdapter extension (references reference; listItem & gt; list item; public listing adapter (reference reference, list & lt; ListItem & gt; listItems) {this.context = context; This.listItems = ListItems;} ... override public view getView (int i, view view, viewgroup viewgroup) {ListItem item = listItems.get (i); return item.getview (reference, layoutfrom.fr (reference))}} < / Code>
Comments
Post a Comment