开发者

android UI change from another thread

I am trying to implement a simple music player 开发者_如何学Pythonin android but my problem is that when trying to update the UI (eg. changing a textview which displays the current position of the song that is being played) it doesn't change smoothly if I use another thread. My problem with a timer is that in the run method I can't change the UI directly. Anyone any suggestions? Thank you


you cant update UI directly in thread and but you can change UI in thread using runOnUiThread method..

like this..

 activity.runOnUiThread(new Runnable() {@Override public void run()
 {
       TextView.setText("hiiiiiiiii");
 }});


From the non UI thread send a Broadcast Intent & populate it with the variables required by the UI & then send it. In the UI thread implement a Broadcast Receiver & let the UI thread update itself.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜