.AppException: android.view.ViewRootImpl$CalledFromWrongThreadException: Only t

错误内容:.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

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。