在另一个类中启动CountDownTimer?

时间:2016-04-15 07:51:18

标签: java android android-studio timer countdowntimer

我有这个计时器类我宣布Countdowntimer,我希望在我的其他类 GameViewlvl3 中启动它,但我不知道如何做到这一点。我看过像我这样的问题,但我不明白答案。它用于学校项目,请帮助我:)。

这是我的计时器

public class Timer {

Content value = new Content();
int time = 60000;
TextView pointsCounter;
TextView timeCounter;
private ImageButton character;
private RelativeLayout screenLayout;

final CountDownTimer countDown = new CountDownTimer(time, 1000) {

    public void onTick(long millisUntilFinished) {

        timeCounter.setText("" + millisUntilFinished / 1000);

        if (millisUntilFinished < 11000)
            timeCounter.setTextColor(Color.argb(255, 255, 0, 0));
    }

    public void onFinish() {
        timeCounter.setText("");
        pointsCounter.setTextColor(Color.argb(255, 255, 0, 0));
        character.setEnabled(false);
        character.setVisibility(character.INVISIBLE);
        screenLayout.setBackgroundResource(R.drawable.failedbg);
    }
};
}

这是我的 GameViewlvl3

public class GameViewLvL3 extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_mainlvl3);
    Content Values = new Content();
    int time = 35000;
}
}

0 个答案:

没有答案