English 中文(简体)
倒数计时器的负秒数怎么减?
原标题:How to minus some second from countdowntimer?
  • 时间:2012-05-27 11:08:38
  •  标签:
  • java
  • android

I am trying a simple counter for a quiz app.here I wanted to minus some second from the timer in the button press.I used a flag which contains a true value..when the button is pressed it become false..then i check the value of the flag and tried to minus some seconds from the timer...bt it is not working. Here is the code that i have tried...

Java 代码 :

package com.okj.hjhu;

import android.app.Activity;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class OkghActivity extends Activity implements OnClickListener {

    TextView tv;
    Button a;
    Boolean flag = true;
    CountDownTimer counter;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

        Initializer();
        setlisteners();

        MyCount counter = new MyCount(120000, 1000);

        counter.start();

    }

    private void setlisteners() {
        // TODO Auto-generated method stub

        a.setOnClickListener(this);

    }

    private void Initializer() {
        tv = (TextView) findViewById(R.id.textView1);

        a = (Button) findViewById(R.id.button1);

    }

    public class MyCount extends CountDownTimer {

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

        }

        @Override
        public void onFinish() {
            tv.setText("done");
        }

        @Override
        public void onTick(long millisUntilFinished) {

            tv.setText("Lef Time ...  00:00:" + millisUntilFinished / 1000);

            if (flag = false) {

                long ty = millisUntilFinished - 9000;

                tv.setText("Lef Time ...  00:00:" + ty / 1000);

            }

        }

    }

    public void onClick(View v) {
        // TODO Auto-generated method stub

        switch (v.getId()) {

        case R.id.button1:
//when the button will be pressed the counter will minus some second from the timer
            flag = false;
            break;

        case R.id.button2:
            break;

        case R.id.button3:
            break;

        case R.id.button4:
            break;

        }

    }
}

帮帮忙...

问题回答

我认为方式是, 您必须使用 反倒计时器取消当前倒计时器的倒计时器 。 cancel (), 然后开始新的计时器 iwth 新的特定时间 /





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签