Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/224.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何设置单击计数以显示对象?_Java_Android - Fatal编程技术网

Java 如何设置单击计数以显示对象?

Java 如何设置单击计数以显示对象?,java,android,Java,Android,我以为我能搞定,但我没有。基本上,我是在计算用户正在做的点击次数,作为测试,我希望每点击三次(点击次数除以3),然后显示一个间隙广告 我意识到的问题是,前三次点击或者第一个数字分成3,它显示了广告。然而,如果我继续点击,广告就再也不会出现了 我做错了什么?如何根据我的点击次数让广告不断出现 public class Content extends AppCompatActivity { Button selectAnotherButton; TextView clickCoun

我以为我能搞定,但我没有。基本上,我是在计算用户正在做的点击次数,作为测试,我希望每点击三次(点击次数除以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.");
                    }
                }

            }
        });


    }



}


你能这样试试吗?顺便说一句,你不应该把你的钥匙贴在这里。

你好,优素福,等我完成工作回家后,我会试试这个答案。谢谢,这会不会引起问题,因为他们说确保给视频足够的时间加载,在这种情况下,初始化的代码不应该在onCreate()中?
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();