我已將TextView
添加到RelativeLayout
,我已將其添加到SurfaceView
。我可以讓TextView
在我的SurfaceView
上顯示文字。從線程更新TextView中的文本
rl = new RelativeLayout(this);
tv = new TextView(this);
tv.setText(Integer.toString(GameScreen.score));
tv.setTextSize(50);
tv.setPadding(390, 50, 0, 0);
tv.setTextColor(Color.BLACK);
rl.addView(renderView);
rl.addView(tv);
setContentView(rl);
然後在我的GameScreen類的更新方法,我把:
game.getTextView().setText(Integer.toString(score));
,它給我的錯誤:
android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
我能做些什麼來解決這個問題?
的可能的複製[Android的 - ViewRootImpl $ CalledFromWrongThreadException(http://stackoverflow.com/questions/10118301/android-viewrootimplcalledfromwrongthreadexception) – rkosegi
感謝rkosegi我讀了它,但是從ANKIT解決方案做了一些感覺,但我直到@MustansarSaeed解釋它不明白它 – Noitidart
可能重複的[Android的更新TextView在線程和運行](http://stackoverflow.com/questions/12716850/android-update-textview-in-thread-and-runnable) – OnePunchMan