android - showing rewarded video ads after click list

前端 未结 2 1614
终归单人心
终归单人心 2021-01-29 13:33

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

相关标签:
2条回答
  • 2021-01-29 14:20

    Updated:

    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);
    
                            }
                        }
                      });
    

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

    0 讨论(0)
  • 2021-01-29 14:20

    Try to use this code :

         Button button = findViewById(R.id.button_id);
         int click = 0 ;
         button.setOnClickListener(new View.OnClickListener() {
             public void onClick(View v) {
                if(click > 3){
                //show ads
                }else{
                 click++ ;
                }
             PreferenceManager.getDefaultSharedPreferences(MainActivity.this)
            .edit().putString(key, value).apply();
    
             }
         });
    
    0 讨论(0)
提交回复
热议问题