.AppException: android.view.ViewRootImpl$CalledFromWrongThreadException: Only t
2014-02-28 16:09
459 查看
错误内容:.AppException: android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
这是在主线程中使用了销毁时间的操作,容易造成ANR;
解决方案:
private void setData() {
if (null != lineInfos) {
LineImageAdapter adapter = new LineImageAdapter(
((AppContext) getActivity().getApplicationContext()),
lineInfos, mGridView);
mGridView.setAdapter(adapter);
mGridView.setOnItemClickListener(new GridItemClickListener());
}
}
改为:private void setData() {
Message message = new Message();
message.what = 5;
handler.sendMessage(message);
}
private Handler handler = new Handler() {
@SuppressWarnings("unchecked")
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case 5:
if (null != lineInfos) {
LineImageAdapter adapter = new LineImageAdapter(
((AppContext) getActivity().getApplicationContext()),
lineInfos, mGridView);
mGridView.setAdapter(adapter);
mGridView.setOnItemClickListener(new GridItemClickListener());
}
break;
default:
break;
}
}
};
这是在主线程中使用了销毁时间的操作,容易造成ANR;
解决方案:
private void setData() {
if (null != lineInfos) {
LineImageAdapter adapter = new LineImageAdapter(
((AppContext) getActivity().getApplicationContext()),
lineInfos, mGridView);
mGridView.setAdapter(adapter);
mGridView.setOnItemClickListener(new GridItemClickListener());
}
}
改为:private void setData() {
Message message = new Message();
message.what = 5;
handler.sendMessage(message);
}
private Handler handler = new Handler() {
@SuppressWarnings("unchecked")
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case 5:
if (null != lineInfos) {
LineImageAdapter adapter = new LineImageAdapter(
((AppContext) getActivity().getApplicationContext()),
lineInfos, mGridView);
mGridView.setAdapter(adapter);
mGridView.setOnItemClickListener(new GridItemClickListener());
}
break;
default:
break;
}
}
};
相关文章推荐
- android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original
- android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original
- android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original
- android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a vi
- Android异常:android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original
- android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a vi
- Android异常:android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original
- E/错误(3907): android.view.ViewRootImpl$CalledFromWrongThreadException: Only the o
- android ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hi
- android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a vi
- android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a v
- android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a vi
- android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a vi
- android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a vi
- 子线程中处理UI,抛异常 android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original
- android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
- 16-07-24 android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that
- android.view.viewroot$calledfromwrongthreadexception: only the original thread that created a view h
- android.view.ViewRootImpl$CalledFromWrongThreadException:
- Unhandled exception: android.view.ViewRootImpl$CalledFromWrongThreadException: