码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-03-06 10:29:37      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:

在调试软件的时候出现如下的错误:

01-05 20:53:36.492: E/ZZShip(2043): android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.

又是一个ThreadException,之前也碰到过。

解决方法:

private Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {

  //这里可以做一些,比如关闭加载对话框

}

}

//--------------------------------------------------------------------

try {
new Thread(new Runnable() {
@Override
public void run() {
try {

//打开加载对话框
//与服务器进行通讯

mHandler.post(runnableUI);


} catch (Exception e) {
Log.e(TAG, e.toString());
}
}
}).start();
} catch (Exception e) {
Log.e(TAG, e.toString());
}

 

//--------------------------------------------------------------------

// 构建Runnable对象,在runnable中更新界面
Runnable runnableUI=new Runnable(){
@Override
public void run() {
  //更新UI

  mHandler.sendEmptyMessage(1);//更新完成以后,发送对话框关闭加载对话框
}
};

 

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

标签:

原文地址:http://www.cnblogs.com/jiduoduo/p/4317424.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!