CountDownTimer调用双方法 [英] CountDownTimer calls double method

查看:133
本文介绍了CountDownTimer调用双方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道该如何解释好。我有这样的定时器,和之后完成计数应该调用另一个类(弹出式),并在同一类的其他功能,其中的柜台后。

 公共类mycount的扩展CountDownTimer {

        公共mycount的(长millisInFuture,长countDownInterval){
            超(mil​​lisInFuture,countDownInterval);
        }


        公共无效onFinish(){

            意图I =新的意图(getApplicationContext(),PogresanOdgovor.class);
            i.putExtra(tacanOdgovor,tacanOdg);
            startActivity(ⅰ);
            mHandler.postDelayed(mLaunchTask,2200);

            brojacPogresnihOdgovora ++;
        }
 

在第一遍,我的成绩是2,而不是1,则6,14 ...这延迟的方法是简单的一个问题:

 的Runnable mLaunchTask =新的Runnable(){
        公共无效的run(){
            下一个问题();
            brojacVremena.start();
        }
     };
 

我称之为完全相同的方法之一onFinish(),当用户回答错了,它工作正常。

mycount的brojacVremena =新mycount的(6000,1000);

最后OnClickListener clickListener =新OnClickListener(){         公共无效的onClick(视图v){

 答ANS =(答案)v.getTag();
        如果(ans.isCorrect){
            brojacVremena.cancel();
            brojacTacnihOdgovora = brojacTacnihOdgovora + 5;
            意图I =新的意向书(rs.androidaplikacijekvizopstekulture.TACANODGOVOR);
            startActivity(ⅰ);
            mHandler.postDelayed(mLaunchTask,1200);
        }
    其他{
        brojacVremena.cancel();
        brojacPogresnihOdgovora ++;
        意图I =新的意图(getApplicationContext(),PogresanOdgovor.class);
        i.putExtra(tacanOdgovor,tacanOdg);
        startActivity(ⅰ);
        mHandler.postDelayed(mLaunchTask,2200);

    }
};
 

解决方案

我发现我的错误。我打电话给我的柜台两次。这里:

  nextQuestion();
brojacVremena.start();
 

和下面在非常相同nextQuestion方法:

 公共无效nextQuestion(){
brojacVremena.start();
。
。
。
 

我不知道如何发生的。

I don't know how to explain better. I have this timer, and after it finish counting it should call another class (popup) and after that other function in the same class where the counter is.

public class MyCount extends CountDownTimer {

        public MyCount(long millisInFuture, long countDownInterval) {
            super(millisInFuture, countDownInterval);
        }


        public void onFinish() {

            Intent i = new Intent(getApplicationContext(), PogresanOdgovor.class);
            i.putExtra("tacanOdgovor", tacanOdg);
            startActivity(i);
            mHandler.postDelayed(mLaunchTask,2200);

            brojacPogresnihOdgovora++;
        }

After first pass, my score is 2 instead of 1, then 6, the 14...This delayed method is simply the next question:

Runnable mLaunchTask = new Runnable() {
        public void run() {
            nextQuestion();
            brojacVremena.start();
        }
     };

I call exactly the same method as the one in onFinish() when user answer wrong and it works fine.

MyCount brojacVremena = new MyCount(6000, 1000);

final OnClickListener clickListener = new OnClickListener() { public void onClick(View v) {

        Answer ans = (Answer) v.getTag();
        if (ans.isCorrect) {
            brojacVremena.cancel();
            brojacTacnihOdgovora = brojacTacnihOdgovora + 5;
            Intent i = new Intent("rs.androidaplikacijekvizopstekulture.TACANODGOVOR");
            startActivity(i);
            mHandler.postDelayed(mLaunchTask,1200);
        }
    else{
        brojacVremena.cancel();
        brojacPogresnihOdgovora++;
        Intent i = new Intent(getApplicationContext(), PogresanOdgovor.class);
        i.putExtra("tacanOdgovor", tacanOdg);
        startActivity(i);
        mHandler.postDelayed(mLaunchTask,2200);

    }
};

解决方案

I found my error. I called my counter twice. Here:

nextQuestion(); 
brojacVremena.start();

and below in the very same nextQuestion method:

public void nextQuestion() {
brojacVremena.start();
.
.
.

I don't know how that happened.

这篇关于CountDownTimer调用双方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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