Android 碎片中使用碎片,用handler更新UI时报错

fuzhaowei 发布于 2016/09/02 10:46
阅读 259
收藏 0
class myrunn implements Runnable {
@Override
public void run() {
list = new ArrayList<String>();
for (int i = 0; i < 40; i++) {
list.add("新闻" + i);
}
handler2.obtainMessage(0x8).sendToTarget();


}
}


Handler handler2 = new Handler() {
public void handleMessage(android.os.Message msg) {
if (msg.what == 0x8) {
adapter = new HorizListViewAdapter(list, getActivity());
browser_horiz_list.setAdapter(adapter);
}


};
};


报错:Can't create handler inside thread that has not called Looper.prepare()



加载中
0
nesger
nesger
你的handler创建在子线程中了。把handler移到主线程就好了。
nesger
nesger
回复 @fuzhaowei : 有帮助麻烦采纳下哦~
f
fuzhaowei
发现了,在子线程中开辟子线程,hand还是在子线程
返回顶部
顶部