How to update Android UI elements from loop while it still looping?
<p>I need to update Android buttons from loop, to make each button highlighted one by one<br>
<img src="http://i.stack.imgur.com/aCVRC.jpg" alt="enter image description here"></p>

<p>I was trying use AsyncTask without success, the same with Handler.<br>
below the Handler example [part from the code, just to give you example]: </p>

<pre><code>for(i=1;i&lt;10;i++){
final int value = i;
Runnable runnable = new Runnable() {
    @Override
    public void run() {
            try {
                Thread.sleep(0);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            handler.post(new Runnable() {
                @Override
                public void run() {
                    Button currentButton = (Button) findViewById(value);
                    currentButton.setPressed(true);

                }
            });
    }
};
new Thread(runnable).start();
</code></pre>

<p>Any Idea how to reach UI elements one by one?<br>
Another example: in below example in standard loop:<br>
 - get button by id<br>
 - setPressed(true) to make the button highlight<br>
 - execute the wanted function<br>
 - setPressed(false), only when the previous step was done.<br>
The problem: while the loop running the buttons doesn't updated, only when the loop finished, in this case the user will not understand what step executed:<br>
the below code is the event of Starting all the loop:  </p>

<pre><code>View.OnClickListener OnClickDoSomething(final Button button)  {
return new View.OnClickListener() {
    public void onClick(View v) {
        button.setText("text now set.. ");
        UpdateStep updateStep;
        for(int i=1; i&lt;stepsArray.size();i++)
      {
         final int value = i;
         Button currentButton = (Button) findViewById(i);
         currentButton.setHighlightColor(0x7f050003);
         currentButton.setPressed(true);

         for(int x=0;x&lt;900000;x++); // will be replaced with the real function

         currentButton.setPressed(false);
      }
    }
};
</code></pre>
