試圖顯示ProgressDialog,但得到: 無法在未調用Looper.prepare()的線程內創建處理程序。不能顯示來自非UI線程的ProgressDialog。如何?
這裏是我的代碼:
public class SocketThread implements Runnable {
BufferedReader in;
private ProgressDialog dialog;
public void run()
{
socket = null;
while (true)
{
// Loop until connected to server
while (socket == null){
dialog = new ProgressDialog(getApplicationContext());
dialog.setMessage("Connecting to " + gatewayString);
dialog.setIndeterminate(true);
dialog.setCancelable(true);
AdvancedMultipleSeriesGraph.this.runOnUiThread(new Runnable() {
public void run() {
dialog.show();
}
});
是否可以解決?
我不知道「Activity.runOnUiThread(...)」方法。很高興現在知道它。 – Sly 2012-02-08 14:58:01
歡迎你 – Blackbelt 2012-02-08 15:03:46
也許我不理解你,但我的代碼是一樣的,你建議: AdvancedMultipleSeriesGraph.this.runOnUiThread(...) – 2012-02-08 15:08:47