android handler textview settext 有数据 放不进
publicHandlermyhandler=newHandler(){publicvoidhandleMessage(Messagemsg){if(msg.what==...
public Handler myhandler = new Handler() {
public void handleMessage(Message msg) {
if (msg.what == 0x001) {
Bundle bundle = msg.getData();
int size = (Integer) bundle.get("listsize");
textView.setText("找到"+size+"个文件");
findViewById(R.id.mainchoose_ll_progoress).setVisibility(View.GONE);
findViewById(R.id.mainchoose_ll_listview).setVisibility(View.VISIBLE);
}
};
}; 展开
public void handleMessage(Message msg) {
if (msg.what == 0x001) {
Bundle bundle = msg.getData();
int size = (Integer) bundle.get("listsize");
textView.setText("找到"+size+"个文件");
findViewById(R.id.mainchoose_ll_progoress).setVisibility(View.GONE);
findViewById(R.id.mainchoose_ll_listview).setVisibility(View.VISIBLE);
}
};
}; 展开
2个回答
展开全部
真没看出来哪里出错了,你说拿到数据了,但是TextView填充不了,在这里空指针,也不是太应该,看不到完整代码,我自己写了个测测看看,
第一段代码:
Message msg = handler.obtainMessage();
Thread.sleep(3000);
Bundle bundle = new Bundle();
bundle.putInt("age", 20);
bundle.putString("name", "json");
msg.setData(bundle);
msg.what = 0x001;
handler.sendMessage(msg);
第二段代码:
if(msg.what == 0x001){
Bundle bundle = msg.getData();
int age = bundle.getInt("age");
String name = bundle.getString("name");
text.setText("年龄:"+age+",姓名:"+name);
}
结果:
正常显示:年龄:20,姓名:json
第一段代码:
Message msg = handler.obtainMessage();
Thread.sleep(3000);
Bundle bundle = new Bundle();
bundle.putInt("age", 20);
bundle.putString("name", "json");
msg.setData(bundle);
msg.what = 0x001;
handler.sendMessage(msg);
第二段代码:
if(msg.what == 0x001){
Bundle bundle = msg.getData();
int age = bundle.getInt("age");
String name = bundle.getString("name");
text.setText("年龄:"+age+",姓名:"+name);
}
结果:
正常显示:年龄:20,姓名:json
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询