2013-12-19 70 views
0

我已經創建了對話框,它膨脹了xml,它獲得了更新的信息。但進度對話框顯示在彈出的對話框後面。如何在對話框的頂部顯示進度對話框,其中包含膨脹的xml。progressdialog進入對話框

public class MainActivity extends Activity { 

    protected void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.activity_main); 


      dialog(); 
     } 


     public class loadasync extends AsyncTask<Void, Void, JSONObject> { 

      ProgressDialog progressDialog ; 
      @Override 
      protected JSONObject doInBackground(Void... params) { 
        } 
      @Override 
      protected void onPreExecute() { 
       // TODO Auto-generated method stub 

       super.onPreExecute(); 
       runOnUiThread(new Runnable() { 
        @Override 
        public void run() { 
          progressDialog = new ProgressDialog(MainActivity.this); 
         progressDialog.setMessage("loading"); 
         progressDialog.setCanceledOnTouchOutside(false); 
         progressDialog.show(); 
        } 
       });   
      } 

      @Override 
      protected void onPostExecute(JSONObject result) { 


       runOnUiThread(new Runnable() { 
        @Override 
        public void run() { 


         progressDialog.dismiss(); 
        }  
       }); 
      } 
     } 



     public void dialog() { 

      dialog = new Dialog(MainActivity.this); 
      dialog.setContentView(R.layout.dialogxml); 

     loadasync loadasyncdata=new loadasync(); 
     loadasyncdata.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); 


      dialog.show(); 


     } 

回答

1

我看不到你在代碼中使用setProgressStyle()。即:

progessDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); 

例如。

因此,在你的代碼嘗試以下操作:

public void run() { 
        progressDialog = new ProgressDialog(MainActivity.this); 
        progressDialog.setMessage("loading"); 
        progressBar.setProgressStyle(ProgressDialog.STYLE_SPINNER); 
        progressDialog.setCanceledOnTouchOutside(false); 
        progressDialog.show(); 
       } 
0

要考慮的事情:OnPostExecute和onPreExecute是在UI線程上都運行,這樣你就可以刪除runOnUIThread的東西,只是做

 protected void onPreExecute() { 
      progressDialog = new ProgressDialog(MainActivity.this); 
      progressDialog.setMessage("loading"); 
      progressDialog.setCanceledOnTouchOutside(false); 
      progressDialog.show(); 
     } 

分別在onPostExecute

 protected void onPostExecute(JSONObject result) { 
      progressDialog.dismiss(); 
     } 

也許應該是一個評論,但信譽...