将AdMob原生广告放入listView [英] Putting an AdMob native ad in a listView

查看:231
本文介绍了将AdMob原生广告放入listView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的应用中使用新的AdMob原生广告功能.我想将原生广告放在listView中,列表中的第20个左右的项目都是一个广告.是否可以通过Native Express广告实现这一目标?还是我必须使用Natve高级广告?

I'd like to use the new AdMob native ad functionality in my app. I want to put a native ad within a listView, where every 20th item or so in the list is an ad. Is it possible to achieve this with a Native Express Ad? Or do I have to use a Natve Advanced Ad?

推荐答案

@Jagjit显示了正确的方法.我会逐步写出来
1.创建您自己的自定义适配器(通过扩展BaseAdapter),该适配器将显示为列表视图项
2.创建另一个用于显示本地广告的布局资源文件(设计应类似于在上一步中创建的自定义适配器)
3.在getView方法中,执行以下操作(用于在第二位置显示广告)

Well @Jagjit has shown the right approach. I will write it step by step
1. Create your own custom adapter (by extending BaseAdapter) which will be shown as listview items
2. Create another layout resource file for showing native ad (design should be similar to the custom adapter created in above step)
3. In the getView method do something as follows (for showing ad at 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);
    ...
    ...
}

此处您的自定义适配器为my_custom_list
您会看到广告正在加载.但是有一个小问题,将不会显示位置1的列表的实际项目.
4.为此,在填充ListView之前,向列表中添加一个额外的项目.我已经使用过ArrayList,所以我可以轻松做到.我的方法如下

Here your custom adapter is my_custom_list
You will see the ads are loading. But there is a small problem, the actual item of list at position 1 will not be shown.
4. For that, add an extra item to the list before populating the ListView. I have used ArrayList so I could do it easily. My approach is as follows

arrayList1.add(1,"ad here");
listview1.setAdapter(new MyAdapter(callerView.getContext(), arrayList1.toArray(new String[arrayList1.size()])));

这篇关于将AdMob原生广告放入listView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆