子线程更新Ui

Android子线程更新Ui

1. handler

private Handler mainHandler= new Handler()
    {//Message可以通过obtain获取
        public void dispatchMessage(android.os.Message msg) {
            if(msg.what == 自定义){
                String title = msg.getData().getString("Result");
                View.setText(title);
            }
        };
    };

2.runOnUiThread

    runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            View.setText("runOnUiThread——Result");
                        }
                    });

你可能感兴趣的:(子线程更新Ui)