2013-05-14 51 views
0
Handler handler = new Handler() { 
    public void handleMessage(Message msg) { 
     super.handleMessage(msg); 
     ReturnShow.setText(sMsg);//ReturnShow EditText 
     ReturnShow.setSelection(ReturnShow.length()); 
    } 
}; 

class ReadThread extends Thread { 
    public void run() { 
     sMsg = "..."; 
     handler.sendMessage(handler.obtainMessage()); 
    } 
} 

每當我運行時,setText行都會有錯誤,我找不到原因了?Android Handler更新界面上的錯誤

感謝您的幫助。

enter image description here

回答

1

確保ReturnShow被設置之前,初始化..

喜歡的東西..

ReturnShow = (EditText)findViewById(R.id.edittext); 
+0

感謝您的答案,但我必須在指定的OnCreate這個值,誤差仍然在 – 2013-05-14 09:10:25

+0

錯誤發生在ReturnShow.setText(sMsg)或ReturnShow.setSelection(ReturnShow.length())? – Nermeen 2013-05-14 09:13:02

+0

oh.i'm愚蠢,我發現錯誤,'ReturnShow =(EditText)findViewById(R.id.ResultShow);'我在這裏使用了一個不正確的ID。謝謝你的回答。 – 2013-05-14 09:38:30