【发布时间】:2010-07-27 12:16:02
【问题描述】:
我有个小问题,希望你能帮帮我;)
问题是,ProgressDialog 仅在加载 run() 后显示,但我需要在启动时显示它并在加载一些数据时显示它。我输入:“dialog = ProgressDialog.show(CategoriesListActivity.this,"Working...","Loading data", true);"在方法 run() 中,但相同。我在 Log.i() 中打印一些信息(int i++)并放置 ProgressDialog 的标题。方法工作正常,但不显示 ProgressDialog。我已经阅读了一些信息,一些线程阻塞了另一个线程(我创建的),这就是为什么不显示progressDialog,但不能做任何事情。谢谢。
public void run() {
/** getting there long execution **/
handler.sendEmptyMessage(0);
}
private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
// stop and hide dialog
dialog.dismiss();
}
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_
dialog = ProgressDialog.show(CategoriesListActivity.this, "Working...",
"Loading data", true);
// start new thread where get long time execution
Thread thread = new Thread(this);
thread.start();
//wait while data is loading, 'cause I need use variable from calculation
// in "EfficientAdapter" later
try {
thread.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
ListView l1 = (ListView) findViewById(R.id.list);
l1.setAdapter(new EfficientAdapter(this));
}
【问题讨论】: