java如何设置单击计数以显示对象?
我以为我能做到这一点,但我没有。基本上,我是在计算用户正在做的点击次数,作为测试,我想每三次点击(点击次数除以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.");
}
}
}
});
}
}
# 1 楼答案
你能这样试试吗?顺便说一句,你不应该把你的钥匙贴在这里