-4

如何创建一个对话框来显示在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);
    }
}
4

2 回答 2

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 */
    }
于 2013-08-16T06:42:00.833 回答
0

试试这个

      private ProgressDialog dialog1;
      dialog1 = ProgressDialog.show(LoginClass.this, "", "Loading...");
于 2013-08-16T06:57:35.110 回答