I have the code below that works, except that it always hides at least one real item in the list, because the ad is displayed at that position.
Example of a problem: I have a list of 4 times, and adView is displayed in position 3. In the view list, I see only 3 times and AdView, the 4th element will not be displayed
I played with an increase in adapter size every time I return an ad, but it doesn’t work very well.
Any ideas?
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());
return row;
}
@Override
public int getCount() {
if (items != null) {
return items.size();
} else {
return 0;
}
}
source
share