Refresh screen while function is being executed
<p>I have a simple function that counts from 0 to 5000 and does funky math with those numbers, and I would like to display progress bar showing where it is currently counting at (each iteration roughly takes 1 second).</p>

<p>My ProgressBar is the following</p>

<pre><code>    &lt;TableRow
        android:visibility="gone"
        android:id="@+id/progress_bar_row" &gt;
        &lt;ProgressBar
            android:id="@+id/progress_bar"
            style="?android:attr/progressBarStyleHorizontal"
            android:layout_width="wrap_content"
            android:layout_span="2"
            android:layout_height="wrap_content" /&gt;
    &lt;/TableRow&gt;
</code></pre>

<p>When user presses button my function starts, it makes the row visible, and I would like to refresh the ProgressBar with each iteration. My function is the following</p>

<pre><code>private void find_number(View v)
{
    String response = "";
    TextView answer = (TextView)findViewById(R.id.answer);
    TableRow progress_bar_row = (TableRow)findViewById(R.id.progress_bar_row);
    ProgressBar progress_bar = (ProgressBar)findViewById(R.id.progress_bar);
    progress_bar.setProgress(0);
    progress_bar.setMax(5000);
    progress_bar_row.setVisibility(View.VISIBLE);

    answer.setText("");
    for(int i = 0; i &lt;= 5000; i++)
    {
        progress_bar.setProgress(i);
                    // a lot of heavy math is being performed here and answer is stored inside response string
    }
    //progress_bar.dismiss();
            progress_bar_row.setVisibility(View.GONE);
    answer.append(response);
}
</code></pre>

<p>I can't seem to figure out a way of going about refreshing the screen. I poked around and got a suggestion to use threads and handlers, I never used threads before, nor would I know how to change my function to adapt to thread use. Or if there is a simpler way without using any threads and simply calling some kind of refresh function I would appreciate it too. Any help or guidance would be very welcome. Thanks in advance</p>
