Android - using runOnUiThread to do UI changes from a thread

后端 未结 5 1228
走了就别回头了
走了就别回头了 2020-12-06 04:18

I am using a custom title view and would like to show/hide a progressbar in the title view when a thread is working.

This is my title view\'s XML

<         


        
5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-06 05:07

    use Communication with Handlers ,

    1. execute your thread
    2. into run() : you should send a message to the Handler which will update the progressBar (Horizontal of course ) : handler.sendMessage(handler.obtainMessage());
    3. in your Activity , you should override the method handleMessage(Message msg ) : like this

      handler = new Handler(){
        @override
        public void handleMessage(Message msg ) 
        {
          //here you write the code which will update your progressBar 
        }
      };
      

提交回复
热议问题