Show milliseconds with Android Chronometer

前端 未结 5 515
深忆病人
深忆病人 2021-01-01 18:44

I\'m looking for a way to make the Chronometer in Android (preferably 1.6 and upwards) show 10ths of a second while counting up.

Is it possible to do this? If not, i

5条回答
  •  自闭症患者
    2021-01-01 18:52

    I have found the way after lots and lots of research. I don't know if it's effective or not, because the truth is that the Emulator crashes after about 10 seconds, but on the phone it runs just fine, and that does it for me. It looks something like this:

    import android.os.Handler;
    public class Chronometer extends Activity {
      private Handler mHandler = new Handler();
    public void actions() {
      mHandler.removeCallbacks(mUpdateTimeTask);
      mHandler.postDelayed(mUpdateTimeTask, 1); //1 is the number of milliseconds you want the text to be updated
    }
    Runnable mUpdateTimeTask = new Runnable() {
      public void run() {
        i++;
        txt.setText(formatTime(i)); // formatTime is just for make it readable in HH:MM:SS:MS, but I assume you already have this
        mHandler.postDelayed(this, 1);
        }
      };
    }
    

提交回复
热议问题