Possible Duplicate:
how to update the textview variable for every 5 seconds
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.
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.
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++;
}
I want the hr value to be updated every 5 sec, without affecting the chart. anyone pls help. Thanks in advance for the help.