错误内容:.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;
}
}
};
我的QQ群:373643359,欢迎加入
.AppException: android.view.ViewRootImpl$CalledFromWrongThreadException: Only t,,5-wow.com