如何在ArrayAdapter的顶视图中添加Admob AdView

时间:2013-12-29 11:12:11

标签: admob android-arrayadapter adview

我创建一个ArrayAdapter类来列出视图中的所有项目,但我想在View顶部添加Admob Adview但不能正常工作。请帮助我。

我的getView功能是:

    @Override
public View getView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub
    LayoutInflater inflater = (LayoutInflater) context
            .getSystemService(context.LAYOUT_INFLATER_SERVICE);
    View rowView = inflater.inflate(R.layout.news_layout, parent, false);
    ImageView iv = (ImageView)rowView.findViewById(R.id.ivIcon);
    TextView tv = (TextView)rowView.findViewById(R.id.tvNews);
    tv.setText(items.get(position).getTitle());
    if(position==0){
        AdView adView = new AdView((Activity)context, AdSize.BANNER,"a152bfd02492f0b");
        adView.loadAd(new AdRequest());
        LinearLayout layout = (LinearLayout)rowView.findViewById(R.id.main_layout);
        layout.addView(adView);
    }

    iv.setTag((String)items.get(position).getLink_img());
    new LoadImageAsyntask().execute(iv);
    return rowView;
}

1 个答案:

答案 0 :(得分:0)

正如Szymon所说 - 请勿尝试将AdView放入ArrayAdapter。你只是在寻求痛苦。重新考虑你的申请。

ArrayAdapters用于类似项目的列表。 AdView应放在持有ArrayAdapter的ListView的上方或下方。