如何将数字 运行 从 60 变为 0 并在 android studio 的 textview 上打印

how to make number running from 60 to 0 and print on textview in android studio

       Runnable r = new Runnable(){
       public void run(){
            try{
                    For (int i = 60; i >= 1; i--) {        
                    System.out.print(i + "\r");
                    // Let the thread sleep for a while.
                    Thread.sleep(1000);
                    TextView box2 = (TextView) findViewById(R.id.box2);
                    box2.setText("\r" + i + " sec left");
                }
            } catch (InterruptedException e) {
            }
        }

如何将数字 运行 从 60 变为 0 并在 android studio 的文本视图中打印以及在 android [=15] 的文本视图中打印的正确方法是什么=]你的帮助!

首先在 onCreate() 中初始化您的 TextView:

TextView box2 = (TextView) findViewById(R.id.box2);

然后您可以使用带有 postDelayed() 方法的处理程序来创建倒数计时器:

final Handler handler = new Handler();
handler.postDelayed(new Runnable(){
    public void run() {
        for (int i = 60; i >= 1; i--) {
            box2.setText("\r" + i + " sec left");
        }
        handler.postDelayed(this, 1000);
    }
}, 0);