-4

How to create a dialog to show loading in android? I want to show a dialog with "Loading..." while an aynctask i running. I tried with an activity with Theme.Dialog. Please help.

my code:

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);
    }
}
cleg
  • 4,862
  • 5
  • 35
  • 52
Electra
  • 3
  • 3

2 Answers2

1

Use ProgressDialog Class to show it.

/*****************************************
 * 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 */
    }
Arun Shankar
  • 2,603
  • 2
  • 26
  • 36
0

Try this

      private ProgressDialog dialog1;
      dialog1 = ProgressDialog.show(LoginClass.this, "", "Loading...");
DJhon
  • 1,548
  • 3
  • 22
  • 39