可能重複:
Android : CalledFromWrongThreadException;: Only the original thread that created a view hierarchy can touch its views如何處理
現在我上application.I工作要以顯示一個進度條,直到我從被調用的方法得到一個真實的回覆。我使用下面的代碼。
progressBar = new ProgressDialog(this);
progressBar.setCancelable(true);
progressBar.setMessage("Loading");
progressBar.show();
new Thread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
final boolean flag= GetFixtureDetailsJsonFunction();
if (flag==true) {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
progressBar.dismiss();
}
}
}).start();
protected boolean GetFixtureDetailsJsonFunction()
{
//some code
return true;
}
但我得到異常
03-14 15:48:23.722: E/AndroidRuntime(910): android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
請幫我的朋友
更新您的問題謝謝...如何我可以更改代碼嗎?處理器類中的 – sarath 2012-03-14 10:52:15
可以調用progressBar.dismiss();然後從線程調用處理程序對象。 – Mayank 2012-03-14 10:56:13