![](/img/trans.png)
[英]how to make count similar id object in list and display in recyclerview?
[英]How to set a click count to display an object?
我以為我已經開始工作了,但是沒有。 基本上,我是在計算用戶正在執行的點擊次數,作為測試,我想說明每三次點擊(點擊數除以3),然后顯示一個非頁內廣告。
我已經意識到的問題是前三個點擊或第一個數字被分成3個,它顯示了廣告。 但是,如果我繼續點擊,那么廣告將不再出現。
我做錯了什么,如何根據點擊次數狀況不斷顯示廣告?
public class Content extends AppCompatActivity {
Button selectAnotherButton;
TextView clickCountText;
int getClickCountInt;
private InterstitialAd mInterstitialAd;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_content);
MobileAds.initialize(Content.this, "ca-app-pub-...");
mInterstitialAd = new InterstitialAd(Content.this);
mInterstitialAd.setAdUnitId("ca-app-pub-.../...");
mInterstitialAd.loadAd(new AdRequest.Builder().build());
final SharedPreferencesManager prefManager = SharedPreferencesManager.getInstance(Content.this);
clickCountText = findViewById(R.id.click_count);
clickCountText.setText(Integer.toString(prefManager.getClicks()));
getClickCountInt = Integer.parseInt(clickCountText.getText().toString());
selectAnotherButton = findViewById(R.id.button_select_another);
selectAnotherButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getClickCountInt++;
clickCountText.setText(Integer.toString(prefManager.increaseClickCount()));
if(getClickCountInt % 3 == 0){
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
} else {
Log.d("ADVERT", "The interstitial wasn't loaded yet.");
}
}
}
});
}
}
private void showAd() {
MobileAds.initialize(Content.this, "your key");
mInterstitialAd = new InterstitialAd(Content.this);
mInterstitialAd.setAdUnitId("your key");
mInterstitialAd.loadAd(new AdRequest.Builder().build());
mInterstitialAd.show();
}
....
if(getClickCountInt % 3 == 0)
showAd();
你可以這樣嘗試嗎? 順便說一句,您不應該在此處發布您的實際密鑰。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.