我想在启动HttpClient的函数上实现一个线程,因为它是根据d.android.com推荐的所以我已经实现了一个线程,但它似乎没有运行,就好像我删除线程代码,我看到的结果。无法在Android中正确实现我的线程
这是我的代码:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.chat_box);// sd
TextView inbox = (TextView) findViewById(R.id.inbox);
final Functions function = new Functions();
final SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(getBaseContext());
where = prefs.getString("chat", "null");
class SendThread extends Thread {
public void run(){
//getInbox() runs an http client
listOfMessages = function.getInbox(where);
}
}
SendThread sendThread = new SendThread();
sendThread.start();
inbox.setText(listOfMessages);
}
就像我上面说的,如果我删除我的线程代码,然后将它完美的作品。关于我在做什么的任何想法都是错误的?这是我第一次使用线程,对于任何新秀错误感到抱歉。
我没有收到任何错误(至少我没有看到任何错误),但是,我没有看到没有插入线程代码的情况下得到的输出。
不要(尝试)从不是UI线程的线程更改UI。另外,'inbox.setText(listOfMessages)'可能在'listOfMessages = function.getInbox(where);'之前执行。 – 2012-04-25 00:36:17
它如何执行?我应该如何改变用户界面,我正在尽力不要触及任何观点。 – EGHDK 2012-04-25 00:43:52