我在位置1和位置4的回收器视图中插入PublisherAdView。现在,如果广告加载失败,我必须删除特定行,例如如果位置1的广告失败,则删除行1或位置4的广告失败然后从回收者视图中删除row4。如何获得广告无法加载的行的正确位置?
private void bindAd(@NonNull final AdItem adItem, final int position) {
PublisherAdView publisherAdView = new PublisherAdView(MyApplication.getContext());
PublisherAdRequest.Builder builder = new PublisherAdRequest.Builder();
publisherAdView.setAdUnitId(adUnitId);
publisherAdView.setCorrelator(correlator);
publisherAdView.loadAd(builder.build());
publisherAdView.setAdListener(new AdListener() {
@Override
public void onAdFailedToLoad(int i) {
super.onAdFailedToLoad(i);
// I have to delete the row here. But , how to get the correct position?
mDataSet.remove(position);
notifyItemRemoved(position);
notifyItemRangeChanged(position, mDataSet.size());
holder.itemView.setVisibility(View.GONE);
}
});
frameLayout.addView(publisherAdView);
}