Update TextView Every Second

前端 未结 9 1292
南旧
南旧 2020-11-28 23:58

I\'ve looked around and nothing seems to be working from what I\'ve tried so far...

    @Override
protected void onCreate(Bundle savedInstanceState) {
    su         


        
9条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-29 00:22

    If you want to show time on textview then better use Chronometer or TextClock

    Using Chronometer:This was added in API 1. It has lot of option to customize it.

    Your xml

    
    

    Your activity

    Chronometer mChronometer=(Chronometer) findViewById(R.id.chronometer);
    mChronometer.setBase(SystemClock.elapsedRealtime());
    mChronometer.start();
    

    Using TextClock: This widget is introduced in API level 17. I personally like Chronometer.

    Your xml

    
    

    Thats it, you are done.

    You can use any of these two widgets. This will make your life easy.

提交回复
热议问题