Putting an AdMob native ad in a listView

后端 未结 4 1176
时光取名叫无心
时光取名叫无心 2020-12-14 03:00

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 possib

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-14 03:53

    The approach is to extend BaseAdapter and create your own custom Adapter, instead of using the default ArrayAdapter. Then you need to return an “Ad” View instead of your usual normal View when you want to display an ad. This means that you need to override getCount() to return more rows (for example if you have 10 rows, that means you need to return 11 = 10 actual content + 1 ad)

    Then you need to decide in which position to create this View, I think you can do it by simply checking the position variable:

    if (position == VALUE) {
       // Create and return Ad View 
    } else {
       // Create and return a normal View 
    }
    

    Hope it helps. I found this as best till yet hope to find better optimised way for this

提交回复
热议问题