Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/189.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
Android 我想显示从60到1之间经过的秒数_Android_Handler - Fatal编程技术网

Android 我想显示从60到1之间经过的秒数

Android 我想显示从60到1之间经过的秒数,android,handler,Android,Handler,我想显示一个从60秒到1秒的文本视图 我应该如何处理事件处理程序 time = GetTime.Showtime(); elapsetime.setText(time + " Secs"); 使用倒计时,使用倒计时,首先,您必须创建并初始化计时器对象: Timer myTimer; myTimer = new Timer(); After that you can call use the schedule method to call timerMethod() (or your met

我想显示一个从60秒到1秒的文本视图

我应该如何处理事件处理程序

time = GetTime.Showtime();
elapsetime.setText(time + " Secs");

使用倒计时,

使用倒计时,

首先,您必须创建并初始化计时器对象:

Timer myTimer;

myTimer = new Timer();

After that you can call use the schedule method to call timerMethod() (or your method). It will the timerMethod() every second (1000 milliseconds).
myTimer.schedule(new TimerTask() {
@Override
public void run() {
timerMethod();
}
}, 0, 1000);

//Runs your doSomething() in the UI Thread

private void timerMethod()
{
this.runOnUiThread(doSomething);
}

// make your doSomething()  runnable

private Runnable doSomething = new Runnable() {
public void run() {
// Your code for doing something
}

首先,您必须创建并初始化计时器对象:

Timer myTimer;

myTimer = new Timer();

After that you can call use the schedule method to call timerMethod() (or your method). It will the timerMethod() every second (1000 milliseconds).
myTimer.schedule(new TimerTask() {
@Override
public void run() {
timerMethod();
}
}, 0, 1000);

//Runs your doSomething() in the UI Thread

private void timerMethod()
{
this.runOnUiThread(doSomething);
}

// make your doSomething()  runnable

private Runnable doSomething = new Runnable() {
public void run() {
// Your code for doing something
}

我使用处理器线程runnable

handler =new Handler();
         runnable = new Runnable() {
            @Override
            public void run() {

                elapsetime.setText(time+" Secs");
                time--;
                if(time<1){
                    handler.removeCallbacks(runnable);
                }else{
                handler.postDelayed(this, 1000);
                }
            }

        };

        handler.postDelayed(runnable, 1000);
handler=newhandler();
runnable=新的runnable(){
@凌驾
公开募捐{
elapsetime.setText(时间+秒);
时间--;

如果(时间我使用处理器线程runnable

handler =new Handler();
         runnable = new Runnable() {
            @Override
            public void run() {

                elapsetime.setText(time+" Secs");
                time--;
                if(time<1){
                    handler.removeCallbacks(runnable);
                }else{
                handler.postDelayed(this, 1000);
                }
            }

        };

        handler.postDelayed(runnable, 1000);
handler=newhandler();
runnable=新的runnable(){
@凌驾
公开募捐{
elapsetime.setText(时间+秒);
时间--;
如果(时间)