2013-08-16 42 views
-4

如何創建一個對話框來顯示在android中加載?我想在運行aynctask時顯示一個對話框「加載...」。我嘗試了與Theme.Dialog的活動。請幫忙。如何在android中顯示「加載...」對話框?

我的代碼:

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

手段是要顯示進度對話框? – Piyush

+0

你的asynctask代碼在哪裏? – Raghunandan

回答

0

使用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 */ 
    } 
+0

謝謝。這是我需要的。我搜索裝載機類,但這正是我的要求 – Electra

0

試試這個

 private ProgressDialog dialog1; 
     dialog1 = ProgressDialog.show(LoginClass.this, "", "Loading...");