I am trying to upgrade my app from listview to recyclerview. When I was using listview I had embedded ads within the listview using this tutorial.
I am not able to add it within recyclerview similarly. Any views on how this is to be done in a Recyclerview?
Currently in my listview the code is as below for loading ads:
if ((position % k) == 0) {
if (convertView instanceof AdView) {
return convertView;
} else {
// Create a new AdView
AdView adView = new AdView(activity, AdSize.BANNER,
ADMOB_ID);
float density = activity.getResources().getDisplayMetrics().density;
int height = Math.round(AdSize.BANNER.getHeight() * density);
AbsListView.LayoutParams params = new AbsListView.LayoutParams(
AbsListView.LayoutParams.FILL_PARENT,
height);
adView.setLayoutParams(params);
adView.loadAd(new AdRequest());
return adView;
}
} else {
return delegate.getView(position - (int) Math.ceil(position / k) - 1,
convertView, parent);
}
This is how it should look:
Update: Refer this video from google, it gives the complete explanation