How to change a TextView every second in Android

后端 未结 5 861
庸人自扰
庸人自扰 2020-12-10 02:52

I\'ve made a simple Android music player. I want to have a TextView that shows the current time in the song in minutes:seconds format. So the first thing I tried was to make

5条回答
  •  一整个雨季
    2020-12-10 03:34

    Use a Timer for this (instead of a while loop with a Thread.Sleep in it). See this article for an example of how to use a timer to update a UI element periodically:

    Updating the UI from a timer

    Edit: updated way-back link, thanks to Arialdo: http://web.archive.org/web/20100126090836/http://developer.android.com/intl/zh-TW/resources/articles/timed-ui-updates.html

    Edit 2: non way-back link, thanks to gatoatigrado: http://android-developers.blogspot.com/2007/11/stitch-in-time.html

提交回复
热议问题