2013-08-16 39 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...");