我有一個有兩列的GridView,我想在每第n行後顯示一個原生廣告。我在互聯網上搜索了很多,但找不到任何解決方案。Android:如何在GridView中每排第n行之後連續顯示AdView?
我已經嘗試了幾個庫/ sdks,如https://github.com/clockbyte/admobadapter,但一直無法解決我的問題。
代碼嘗試:
public View getView(final int position, View row, ViewGroup parent) {
MyHolder holder = null;
boolean showAd = proVersion == false && (position % 8 == k);
if (showAd) {
AdView adView = adList.get(position);
if (adView == null) {
AdView adViewNew = new AdView((Activity) context, AdSize.BANNER, context.getResources().getString(
R.string.adId));
adViewNew.loadAd(Utils.getAdRequest("gps", lat, lng, keywords));
adList.add(position, adViewNew);
return adViewNew;
} else {
return adView;
}
} else if (row == null || row instanceof AdView) {
LayoutInflater inflater = ((SherlockActivity) context).getLayoutInflater();
row = inflater.inflate(viewResourceId, parent, false);
holder = new MyHolder();
holder.textName = (TextView) row.findViewById(R.id.name);
row.setTag(holder);
} else {
holder = (MyHolder) row.getTag();
}
holder.textName.setText(items.get(position).getName());
// more code
return row;
}
I want to achieve something like this:
你有沒有試過?我的意思是不只是lib網址,但代碼 – Vyacheslav
@Vyacheslav我提供了一個代碼嘗試以及 –
是'if(showAd){'被解僱或沒有? – Vyacheslav