如何在android中创建一个显示加载的对话框?我想在运行aynctask时显示一个带有“正在加载...”的对话框。我尝试使用Theme.Dialog
的活动。请帮忙。
我的代码:
private class getlisttask extends AsyncTask<Void, Void, String> {
@Override
protected String doInBackground(Void... arg0) {
SourceURL srcGrabber = new SourceURL ();
String result = "";
try {
Url = Url + usr + "&qry=" + query;
result = srcGrabber.grabSource(Url);
} catch (Exception e) {
Log.e("Exception", e.tostring());
}
return result;
}
@Override
protected void onPostExecute(String result) {
TextView txtView1 = (TextView) findViewById(R.id.TextView);
txtView1.setText(result);
}
}
答案 0 :(得分:1)
使用ProgressDialog类来显示它。
/*****************************************
* AsyncTask Class to Parse and Display
******************************************/
class AsyncTaskClassName extends AsyncTask<Void,Void, Void>{
ProgressDialog progressDialog = null;
/* ***********************************
* Pre-Execute Method
* ********************************** */
@Override
protected void onPreExecute() {
progressDialog = util.getProgressDialog(ActivityClassName.this, "Please wait...", "Parsing List... ");
//ActivityClassName -> The Name of the Activity Class you want to show ProgressDialog
// progressDialog.hide();
progressDialog.show();
/* Do your Pre-Execute Configuration */
}
/* ***********************************
* Execute Method
* ********************************** */
@Override
protected Void doInBackground(Void... arg0) {
/* Do yourxec Task ( Load from URL) and return value */
return null;
}
/* ***********************************
* Post-Execute Method
* ********************************** */
@Override
protected void onPostExecute(Void result) {
progressDialog.dismiss();
/* Do your Post -Execute Tasks */
}
答案 1 :(得分:0)
试试这个
private ProgressDialog dialog1;
dialog1 = ProgressDialog.show(LoginClass.this, "", "Loading...");