title: postDelayed handler with loop
body: <p>I did some research and tried some code including the code below from <a href="https://stackoverflow.com/questions/39024588/android-postdelayed-handler-inside-a-for-loop">Android postDelayed Handler Inside a For Loop?</a>. </p>
  
  <pre><code>final Handler handler = new Handler(); 
  
  
      int count = 0;
      final Runnable runnable = new Runnable() {
          public void run() { 
  
              // need to do tasks on the UI thread 
              Log.d(TAG, "runn test");
  
  
              if (count++ &lt; 5)
                  handler.postDelayed(this, 5000);
  
          } 
      }; 
  
      // trigger first time 
      handler.post(runnable);
  </code></pre>
  
  <p>But the count variable will show an error because it is accessed within the inner class. How can I solve the problem?</p>