android-在点击列表后显示奖励视频广告 [英] android - showing rewarded video ads after click list

查看:87
本文介绍了android-在点击列表后显示奖励视频广告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在主页上有一个项目列表,单击后将转到活动详细信息。在此之前,我想添加奖励视频广告,但是在用户3次单击项目列表后有一个限制后,广告将出现。
有什么建议可以使它变得如此吗?
共享首选项的类似功能?

I have a list of items at homepage and when clicked will go to the activity detail. Before that I want to add Rewarded Video Ads, but with a limit after the user 3x click on the item list the ads will appear. Any suggestions for making it like that? or Similar features of Shared Preferences maybe?

更新:
我已经尝试过使用下面的代码运行,但这并不计算单击的每个列表。.

UPDATE: I have try to run with below code, but this does not count every list that is clicked..

class ViewHolder extends RecyclerView.ViewHolder {
        private TextView tvTitle;
        private LinearLayout rowLayout;

        ViewHolder(View itemView, final Context ctx) {
            super(itemView);
            mContext = ctx;
            tvTitle = itemView.findViewById(R.id.tvTitle);
            rowLayout = itemView.findViewById(R.id.rowLayout);

               itemView.setOnClickListener(new View.OnClickListener() {
               int clickCount = 1;
                    @Override
                    public void onClick(View v){
                        if(clickCount > 3) {

                          if(mRewardedVideoAd.isLoaded()){
                            mRewardedVideoAd.show();
                        }
                            clickCount = 0;
                        } else {

                            clickCount++;
                        Intent intent = new Intent(mContext, DetailsActivity.class);
                        intent.putExtra("title", dataList.get(getAdapterPosition()));
                        intent.putExtra("preview", previewList.get(getAdapterPosition()));
                        ctx.startActivity(intent);

                        }
                    }
                  }
                 }
                });

它应适用于所有所有单击的列表,而不仅仅是计数的每个列表。

It should apply to all every clicked lists, not just for the list per item counted.

推荐答案

已更新:

itemView.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v){
int clickCount = mPreference.getInt("count",0);
                        if(clickCount > 3) {

                          if(mRewardedVideoAd.isLoaded()){
                            mRewardedVideoAd.show();

                        }
                             mPreference.edit().remove("count").apply();

                        } else {

                            clickCount++;
mPreference.edit().putInt("count",clickCount).apply();
                        Intent intent = new Intent(mContext, DetailsActivity.class);
                        intent.putExtra("title", dataList.get(getAdapterPosition()));
                        intent.putExtra("preview", previewList.get(getAdapterPosition()));
                        ctx.startActivity(intent);

                        }
                    }
                  });

为什么不在ViewHolder类中使用自定义界面而不是这样做!

Why don't you use custom interface in your ViewHolder class rather than doing this !

这篇关于android-在点击列表后显示奖励视频广告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆