【问题标题】:Changing TextView dynamically with time in Android在 Android 中随时间动态更改 TextView
【发布时间】:2014-10-05 11:37:02
【问题描述】:

我是安卓初学者。我想随着时间改变我的文本视图。 我的活动持续 5 秒,我想显示倒计时时间。 我尝试使用线程计时器,但它不起作用。 只是我想显示这样的数字

一开始:5, 一秒钟后:4, 2秒后:3, ,, : 2, ,, : 1,

请建议我如何编码。

【问题讨论】:

    标签: android-activity textview android-2.2-froyo


    【解决方案1】:

    使用倒计时:

    @Override
    protected void onCreate(final Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    
        final TextView txtCount = (TextView) findViewById(R.id.txtCount);
    
        final int secs = 5;
        new CountDownTimer((secs +1) * 1000, 1000) // Wait 5 secs, tick every 1 sec
        {
            @Override
            public final void onTick(final long millisUntilFinished)
            {
                txtCount.setText("" + (int) (millisUntilFinished * .001f));
            }
            @Override
            public final void onFinish()
            {
                txtCount.setText("GO!");
            }
        }.start();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-11-18
      • 1970-01-01
      • 1970-01-01
      • 2011-12-26
      • 1970-01-01
      • 2020-10-05
      • 1970-01-01
      相关资源
      最近更新 更多