2016-01-20 91 views
0

在我的android應用程序在循環中連續調用一個API,然後進度對話框會產生一個像外觀一樣的陰影。我認爲問題是多個對話正在運行..幫助我避免這個陰影。下面的代碼給出:Android ProgressDialog陰影出現

for(int i = indexOfSelectedId + 1 ; i < photoall_id.size(); i++) 
     { 
      all_postid.add(photoall_id.get(i)); 
      url = URLS.BASEURL + "mobile_api.php?action=post&post_id=" +posoall_id.get(i)+user_id="+userid; 

      new GetImage().execute(url); 


     } 
private class GetImage extends AsyncTask<String, Void, ArrayList<String>> { 

     String json = null; 
     ProgressDialog dialog; 

     @Override 
     protected void onPreExecute() { 
      all_data=new ArrayList<>(); 
      dialog = new ProgressDialog(FullScreenActivity.this); 
      dialog.setMessage("Loading Image..."); 
      dialog.setCanceledOnTouchOutside(false); 
      dialog.setCancelable(false); 
      dialog.show(); 
      super.onPreExecute(); 
     } 

     @Override 
     protected void onPostExecute(ArrayList<String> aVoid) { 


      dialog.dismiss(); 


      all_url.add(aVoid.get(0)); 


     } 

     @Override 
     protected ArrayList<String> doInBackground(String... params) { 

      JSONReader reader = new JSONReader(); 
      json = reader.getJsonGET(params[0]); 

      if (json != null) { 
       try { 
        JSONObject object = new JSONObject(json); 
        if (object.getJSONArray("posts").getJSONObject(0).getInt("count") != 0) { 
         photo_url = object.getJSONArray("posts").getJSONObject(0).getString("photo_url"); 

        } 
} 

提前

回答

2

推薦solution.Thanks爲避免多次對話框顯示:

public void showProgress(String msg) 
{ 
    if(dialog == null){ 
     dialog = new ProgressDialog(this); 
     dialog.setTitle(null); 
     dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); 
     dialog.setCancelable(false); 
     dialog.setCanceledOnTouchOutside(false); 
    } 

    if(dialog.isShowing()) 
    { 
     dialog.dismiss(); 
    } 

    dialog.setMessage(msg); 
    dialog.show(); 
} 

public void dismissProgress() 
{ 
    if(dialog != null && dialog.isShowing()) 
     dialog.dismiss(); 
} 
+0

謝謝你,它的工作。 – krishna