“Only the original thread that created a view hierarchy can touch its views.” error when using TimerTask

后端 未结 2 1204
忘了有多久
忘了有多久 2021-01-29 09:46

I have created an app composed of one single activity which include a single TextView. Here is the XML of my activity :

activity_main.xml

2条回答
  •  心在旅途
    2021-01-29 10:44

    You need to perform

    text.setText("test");

    in UI thread. You can do so using Handlers.

    final Handler myHandler = new Handler();
    myHandler.post(myRunnable);
    
    
    
       final Runnable myRunnable = new Runnable() {
          public void run() {
            text.setText("test");
          }
       };
    

提交回复
热议问题