Only the original thread that created a view hierarchy can touch its views.

之前遇到过这个问题,当时的解决方法是再UI线程或主线程进行view相关操作,如果想要在view进程要在子线程之后进行,就需要阻塞主线程。

解决方法:使用Handler对象。子线程结束后发送信息

        Thread thread1 = new Thread(new Runnable() {
            @Override
            public void run() {
            ........
            ........
            ........
                Message msg = new Message();
                msg.what = 1;
                handler.sendMessage(msg);
            }
        });
        thread1.start();
    }

    private Handler handler = new Handler(){
        public void handleMessage(Message msg) {
            //一些work线程不能处理的UI逻辑....例如 自动点击view
            iv_search.performClick();
        }
    };

参考:

解决Only the original thread that created a view hierarchy can touch its views_qq_41072388的博客-CSDN博客

解决Only the original thread that created a view hierarc_Jobinqu_新浪博客 (sina.com.cn)

关于android中Handler对象的讲解_恒安软件-CSDN博客

原文地址:https://www.cnblogs.com/Arisf/p/14884301.html