在我的OnCreate方法中,我創建了一個偵聽傳入消息的線程!從線程更新textView
In OnCreate() {
//Some code
myThread = new Thread() {
@Override
public void run() {
receiveMyMessages();
}
};
myThread.start();
// Some code related to sending out by pressing button etc.
}
Then, receiveMyMessage() functions…
Public void receiveMyMessage()
{
//Receive the message and put it in String str;
str = receivedAllTheMessage();
// << here I want to be able to update this str to a textView. But, How?
}
我檢查了this article但它沒有爲我工作,沒有運氣!
大家好,謝謝,非常感謝您的寶貴時間。但沒有運氣!我正在嘗試重寫我的問題: - (與原始問題一起) 在線程中的OnCreate中調用了receiveMyMessage()!這意味着這個receiveMyMessage是在一個單獨的線程中。在這個線程中,我有一個while循環,那就是閱讀是否有任何消息! 公共無效receiveMessages(){ while循環(條件) { STR = receivedAllTheMessage(); //現在,在這裏我要tv.settext更新GUI元素...等等。在這個答案 } } – 2011-03-23 11:23:46
**額外提示:**你可以跳過使用活動的創建單獨的處理程序處理器對象。 'handler = getWindow()。getDecorView()。getHandler();' – Kent 2013-04-11 22:57:13
@Kent該提示可能會或可能不會工作,具體取決於您使用它的位置。我在互聯網上的其他地方發現了這個提示,並利用它,然後當我在程序中更改了某些內容時,它突然不再工作了。有關詳細信息,請參閱此處:http://codereview.stackexchange.com/a/114723/92925 – RenniePet 2015-12-22 07:10:40