title: Android Asynctask update UI and computation
body: <p>I am a beginner at android/java development and I have just started learning about asynctask. I am trying to create an application that counts up (updating the ui thread with each incremental count) with a variable delay, and I am not sure how to pass the values into the asynctask, or even get it to work.</p>
  
  <pre><code>/*I have an editText (I used editText on purpose) named log, which is supposed 
  to be the output of the operation. 
  count is the number of counting up that I want the log to display. 
  time is the sleep delay I wish to set inbetween printing each number.*/
  
      public class backgroundsend extends AsyncTask&lt;String, Integer, String&gt;{
      @Override
      protected String doInBackground(String... params) {
  //and I want i to be the current count of the number to be displayed.
         for (int i=1; i&lt;count+1; i++){
              try {
                  runOnUiThread(new Runnable() {
                      @Override
                      public void run() {
                          log.setText(log.getText() +i);
                      }
                  });
                  Thread.sleep(time);
              } catch (InterruptedException e) {
                  e.printStackTrace();
              }
          return null;
      }
      @Override
      protected void onProgressUpdate(Integer... values) {
      }
      @Override
      protected void onPostExecute(String result){
          log.setText(log.getText() + "Operation Ended \n\n");
      }
  }
  </code></pre>
  
  <p>Now this code does not compile properly because it wants i to be a final variable, and I don't know how to make the i in for loop into a final variable, if possible. I tried using a dummy variable and adding +1 every loop run and it still doesn't work. Additionally, when I tried to use the for loop/asynctask without the i value (a constant value) it would run but the ui thread would still hang like normal on large values. Can somebody give me insight as to what I am doing wrong, and how I should correct it? Thank you.</p>