我有一个小问题,我希望你能帮助我。)ProgressDialog在线程工作在Android
麻烦的是,这ProgressDialog只显示加载的run()之后,但我需要证明它在启动和显示它在加载一些数据时。我把:“dialog = ProgressDialog.show(CategoriesListActivity.this,”工作...“,”加载数据“,真);”在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));
}