0

我在onCreate的主要活動中創建了一個EditText對象。我需要能夠從SurfaceView線程更改佈局參數。目前我收到此錯誤:從SurfaceView線程更新EditText LayoutParams?

android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views. 

我也嘗試從UIHandler設置佈局參數,但我得到相同的錯誤。我對Android開發真的很陌生,所以我非常感謝任何建議。謝謝!

回答

3

一般而言,您可以使用runOnUiThread從其他線程更新UI。例如

runOnUiThread(new Runnable() { 
    public void run() { 
    textView.setText("Hello"); 
    } 
}); 
+0

美麗,謝謝! – 2012-01-07 17:46:28