title: Android progress bar for method
body: <p>I have a custom method of my class that (on my Android phone) takes 2-3 second to finish, and I would like to surround it with a progress bar.</p>
  
  <p>Here is my method:</p>
  
  <pre><code>public void getQuestionsForSelectedCategory(){
      ArrayList&lt;Question&gt; temp = (ArrayList&lt;Question&gt;) this.clone();
      ArrayList&lt;Question&gt; tempGroup;
      this.clear();
      for(int i=0;i&lt;2;i++){
          tempGroup = new ArrayList&lt;Question&gt;();
          for(int j=0;j&lt;temp.size();j++)
              if((temp.get(j).getGroup()==i+1)&amp;&amp;(temp.get(j).getCategory().contains(category)||temp.get(j).getCategory().equals("*")))
                  tempGroup.add(temp.get(j));
          getQuestionsForSelectedGroup(tempGroup, numbersByGroup[i], pointsByGroup[i]);
      }
  
      tempGroup = new ArrayList&lt;Question&gt;();
      for(int i=0;i&lt;temp.size();i++){
          int a = temp.get(i).getGroup();
          if((a==3||a==4||a==5||a==6||a==7))
              if(temp.get(i).getCategory().contains(category)||temp.get(i).getCategory().equals("*"))
                  tempGroup.add(temp.get(i));
      }
      Collections.shuffle(tempGroup);
      getQuestionsForSelectedGroup(tempGroup, numbersByGroup[2], pointsByGroup[2]);
  
      if(category.equals("C")){
          tempGroup = new ArrayList&lt;Question&gt;();
          for(int i=0;i&lt;temp.size();i++)
              if(temp.get(i).getCategory().equals(category))
                  tempGroup.add(temp.get(i));
          getQuestionsForSelectedGroup(tempGroup, 10, 30);
      }
  }
  </code></pre>
  
  <p>And here is what I try to do:</p>
  
  <pre><code>barProgressDialog = new ProgressDialog(this);
      barProgressDialog.setTitle("Preparing Test");
      barProgressDialog.setMessage("Preparing Test");
      barProgressDialog.setProgressStyle(barProgressDialog.STYLE_HORIZONTAL);
      barProgressDialog.setProgress(0);
      barProgressDialog.setMax(100);
      barProgressDialog.show();
  
      new Thread(new Runnable() {
          @Override
          public void run() {
              try {
                  getQuestionsForSelectedCategory();
                  while (barProgressDialog.getProgress() &lt;= barProgressDialog.getMax()) {
                      updateBarHandler.post(new Runnable() {
                          public void run() {
                              barProgressDialog.incrementProgressBy(2);
                            }
                        });
                      if (barProgressDialog.getProgress() == barProgressDialog.getMax()) {
                          barProgressDialog.dismiss();
                      }
                  }
              } catch (Exception e) {
              }
          }
      }).start();
  }
  </code></pre>
  
  <p>For the current code the progress bar fills up to 100 but it does nothing.</p>