title: How to make progress bar running on for loop
body: <p>I have this method to get data from server using volley and store it into sqlite database using ormlite. I'm doing this on splash screen. so now I want to show some progressbar when this process happen, the progress bar already appear and now I want to set the progress of progress bar inside the for loop. But I dont know why my progress bar keep on 0% until the process finish. when I look at the log the progress keep update but maybe because it inside a loop the progress not appear. How can I make the progress appear in my progressdialog?? below is my code   </p>
  
  <pre><code> private void fetchMOffice() {
              mOfficeAdapter = new TableMOfficeAdapter(this);
              List&lt;TableMOffice&gt; listOffice = mOfficeAdapter.getAllDatabyLup();
  
          progressBar = new ProgressDialog(SplashScreenActivity.this);
          progressBar.setCancelable(true);
          progressBar.setMessage("Downloading File...");
          progressBar.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
          progressBar.setProgress(0);
          progressBar.setMax(100);
          showDialog();
  
          for (int i=0; i&lt;listOffice.size(); i++) {
              TableMOffice item = listOffice.get(i);
              lupMOffice = item.getLup();
              //  locationIdArray.add(item.getKode_office());
              break;
          }
          Log.e(TAG, "lup fetchMOffice: " +lupMOffice );
  
          StringRequest strReq = new StringRequest(Request.Method.POST,
                  ConnectionManager.MASTER_M_OFFICE, new Response.Listener&lt;String&gt;() {
  
  
              @Override
              public void onResponse(String response) {
                  Log.e(TAG, "response: " + response);
  
  
  
                  try {
                      JSONObject obj = new JSONObject(response);
                      dbAdapter = new TableMOfficeAdapter(SplashScreenActivity.this);
                      //  dbAdapter.deleteAll();
                      //   SQLiteStatement insert = mDb.compileStatement(sql);
  
                      // check for error flag
                      if (obj.getBoolean("error") == false) {
                          jsonArray = obj.getJSONArray("m_office");
  
  
  
                          for ( i = 0; i &lt; jsonArray.length(); i++) {
  
                                  JSONObject versionObj = null;
  
                                  versionObj = (JSONObject) jsonArray.get(i);
                                  int id = versionObj.getInt("id");
                                  String office = versionObj.getString("office");
                                  String kode_office = versionObj.getString("kode_office");
                                  String channel = versionObj.getString("channel");
                                  String jenis = versionObj.getString("jenis");
                                  String alamat = versionObj.getString("alamat");
                                  String kota = versionObj.getString("kota");
                                  String propinsi = versionObj.getString("propinsi");
                                  String pic = versionObj.getString("pic");
                                  String pic_phone = versionObj.getString("pic_phone");
                                  String map_lat = versionObj.getString("map_lat");
                                  String map_lng = versionObj.getString("map_lng");
                                  String upd = versionObj.getString("upd");
                                  String lup = versionObj.getString("lup");
                                  String ket = versionObj.getString("ket");
                                  String region = versionObj.getString("region");
                                  String rek = versionObj.getString("rek");
                                  String bank = versionObj.getString("bank");
                                  String rental = versionObj.getString("rental");
                                  Log.e("isitabeloffice",   Integer.toString(id));
                                  ctx = getApplicationContext();
                                  dbAdapter.delete(SplashScreenActivity.this,id);
                                  //dbAdapter.delete(ctx,id);
                                  dbAdapter.insertData(new TableMOffice(), id, office, kode_office, channel,
                                          jenis, alamat, kota, propinsi, pic, pic_phone, map_lat, map_lng,
                                          upd, lup, ket, region, rek, bank, rental);
  
                                  progress = (i+1)*100/jsonArray.length();
                                  progressBar.setProgress(progress);
                                  }
  
                      } else {
  
                      }
  
                  } catch (Exception e) {
                      Log.e(TAG, "json parsing error: " + e.getMessage());
                      //Toast.makeText(SplashScreenActivity.this, "Json parse error: " + e.getMessage(), Toast.LENGTH_LONG).show();
                  }
              }
          }, new Response.ErrorListener() {
  
              @Override
              public void onErrorResponse(VolleyError error) {
                  NetworkResponse networkResponse = error.networkResponse;
                  Log.e(TAG, "Volley error: " + error.getMessage() + ", code: " + networkResponse);
                  hideDialog();
                  //Toast.makeText(SplashScreenActivity.this, "Volley error: " + error.getMessage(), Toast.LENGTH_SHORT).show();
              }
          })
          {
              @Override
              protected Map&lt;String, String&gt; getParams() {
                  Map&lt;String, String&gt; params = new HashMap&lt;&gt;();
  
  
                  Log.e(TAG, "params: " + params.toString());
                  return params;
              }
          };
  
          MyApplication.getInstance().addToRequestQueue(strReq);
      }
  </code></pre>