我在onCreateViewHolder上调用了一次AdRequest.Builder()。build(),再次在RecyclerView.Viewholder中调用。
195个请求(100%匹配,仍然只显示5次展示)。我看到很多问题,印象是在40-60%的请求之间,他们说这是正常的。在我的情况下,只有2.5%的请求变成了展示次数。
这是调用adRequests的正确方法吗?我究竟做错了什么?
public class NewsAdapter extends RecyclerView.Adapter<NewsAdapter.NewsViewHolder> {
public NewsAdapter(Context mContext, List<News> newsList) {
this.mContext = mContext;
this.newsList = newsList;
}
@Override
public NewsViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater inflater = LayoutInflater.from(mContext);
View view = inflater.inflate(R.layout.news, null);
RecyclerView.LayoutParams lp = new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
view.setLayoutParams(lp);
NewsViewHolder holder = new NewsViewHolder(view);
mInterstitialAd = new InterstitialAd(mContext);
mInterstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
mInterstitialAd.loadAd(new AdRequest.Builder().build());
Base.initialize(mContext);
return holder;
}
class NewsViewHolder extends RecyclerView.ViewHolder {
TextView headlineView, sourceView, sectionView, timeView, descriptionView;
ImageView imageView, shareView;
LinearLayout newsLayout, innerLinearLayout;
public NewsViewHolder(View itemView) {
super(itemView);
headlineView = itemView.findViewById(R.id.headlines_textview);
sourceView = itemView.findViewById(R.id.news_source_textview);
timeView = itemView.findViewById(R.id.time_textview);
descriptionView = itemView.findViewById(R.id.description_textview);
imageView = itemView.findViewById(R.id.news_imageView);
newsLayout = itemView.findViewById(R.id.linearLayout_news);
innerLinearLayout = itemView.findViewById(R.id.headline_details_linearlayout);
shareView = itemView.findViewById(R.id.share_imageview);
descriptionView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
clicked++;
if (clicked % 3 == 0) {
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
}
}
mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdClosed() {
mInterstitialAd.loadAd(new AdRequest.Builder().build());
}
});
}
});
}
}
}