我开发了一个android应用程序。在那个应用程序从web获取信息并显示在屏幕上。在获取信息的时候,我想在获得信息后将进度对话框加载到屏幕上,我想关闭对话框如何在android中加载进度对话框?
请任何一个可以帮助我如何使用一些示例代码做事先
感谢
我开发了一个android应用程序。在那个应用程序从web获取信息并显示在屏幕上。在获取信息的时候,我想在获得信息后将进度对话框加载到屏幕上,我想关闭对话框如何在android中加载进度对话框?
请任何一个可以帮助我如何使用一些示例代码做事先
感谢
您需要实施AsyncTask
。 例子:
class YourAsyncTask extends AsyncTask<Void, Void, Void> {
private ProgressDialog progressDialog;
@Override
protected void onPreExecute() {
//show your dialog here
progressDialog = ProgressDialog.show(this, "title", "message", true, false)
}
@Override
protected Void doInBackground(Void... params) {
//make your request here - it will run in a different thread
return null;
}
@Override
protected void onPostExecute(Void result) {
//hide your dialog here
progressDialog.dismiss();
}
}
然后你只需要调用
new YourAsyncTask().execute();
你可以阅读更多关于AsyncTask
这里:http://developer.android.com/reference/android/os/AsyncTask.html
的一点是,你应该使用两个不同的线程1日是UI线程,第二次是“装载数据线” 从第2个线程将过程状态发布到第1个线程,例如:仍在工作或完成50% use this to post data
我的意思是progressBar.setCurrentState(50)或progressBar.dismiss()的时候完成... – 2011-06-07 17:26:00