Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了定期更新Android TextView以显示倒计时大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图在 Android使用COuntDownTimer来使TextView从100倒数到零.我希望尽快发生,同时保持可见.

目前,如果CountDownTimer滴答间隔小于500毫秒(我认为就是这样,可能会低一点),那么更新就不会发生.

我只在模拟器上试过这个.

我是否以正确的方式解决这个问题?如果我是,这种明显的缓慢是模拟器的限制还是我必须忍受的东西?如果这不是正确的方法,有人可以推荐一种不同的方法吗?

解决方法

请在模拟器和模拟器上检查以下示例代码.设备
package com.sample;

import android.app.Activity;
import android.os.bundle;
import android.os.CountDownTimer;
import android.widget.TextView;

public class SampleTimer extends Activity {

    TextView tv; // textview to display the countdown

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceStatE) {
        super.onCreate(savedInstanceStatE);
        tv = new TextView(this);
        this.setContentView(tv);

         // 10000 is the starTing number (in milliseconds)
        // 1000 is the number to count down each time (in milliseconds)

        MyCount counter = new MyCount(10000,1000);
        counter.start();
    }


    // countdowntimer is an abstract class,so extend it and fill in methods
    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("Left: " + millisUntilFinished / 1000);
        }
    }
}

大佬总结

以上是大佬教程为你收集整理的定期更新Android TextView以显示倒计时全部内容,希望文章能够帮你解决定期更新Android TextView以显示倒计时所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。