How to use an Android Handler to update a TextView in the UI Thread?

前端 未结 2 1348
星月不相逢
星月不相逢 2020-11-30 07:11

I want to update a TextView from an asynchronous task in an Android application. What is the simplest way to do this with a Handler?

There

2条回答
  •  醉酒成梦
    2020-11-30 07:40

    You can also update UI thread from background thread in this way also:

    Handler handler = new Handler(); // write in onCreate function
    
    //below piece of code is written in function of class that extends from AsyncTask
    
    handler.post(new Runnable() {
        @Override
        public void run() {
            textView.setText(stringBuilder);
        }
    });
    

提交回复
热议问题