Update ListView in the main thread from another thread

前端 未结 6 809
北恋
北恋 2020-12-08 08:34

I have a separate thread running to get data from the internet. After that, I would like to update the ListView in the main thread by calling adapter.notifyDataSetChanged().

6条回答
  •  粉色の甜心
    2020-12-08 09:11

    Or, post a message to the listview's message queue (which would execute on the UI thread):

    list.post(new Runnable() {                  
        @Override
        public void run() {
           adapter.notifyDataSetChanged();
    
        }
    }); 
    

提交回复
热议问题