how to update the textview in a while loop for every 5 seconds without affecting the loop execution and the main activity
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/14476476/how-to-update-the-textview-variable-for-every-5-seconds">how to update the textview variable for every 5 seconds</a>  </p>
</blockquote>



<p>i have two tasks to do simultaneously using the same data file.One is to read the txt file and plot it in the chartview. The other task is to do calculations with the plotted data. My android app layout should have these calculated results in textview above the chartview and it should get updated constantly for 5 sec while the ploting is going on dynamically in the chart. </p>

<p>I have problem with the second task - updating the values in textview which runs in a while loop. I have used Handler,Asynctask,Thread, Wait. It works perfectly as java app.But, it dint work as an android app. My app either force closes or takes the delay before startup (i.e.) the app opens only after the delay given and shows the last value of while loop execution. I also did this in background, but it affects the plotting.</p>

<pre><code>   while(p[y1]!=0)
 {
    rr = ((p[y1]-p[y1-1]));
    double x = rr/500;
    HR = (int) (60/x);                         
     final Handler handler=new Handler();
      handler.post(runnable);
          final Runnable runnable=new Runnable()
          {
          @Override
          public void run()
          {                      
                  hr.setText(String.valueOf(HR));
                handler.postDelayed(runnable, 5000);
          }
          };

          y1++;
            }
</code></pre>

<p>I want the hr value to be updated every 5 sec, without affecting the chart. anyone pls help. Thanks in advance for the help.</p>
