Q:

Is there a way to change text in a TextView while the java code runs? 

I have a TextView in an XML layout (in an Android application).  This TextView displays the value of of a string in strings.xml.  However, as my java code runs I want the value of that string to change each second for 4 consecutive seconds and I want the XML layout to show that change. 
Is there a way to change the value of the string in strings.xml while the java code runs?  If not is there an alternative way to change the text displayed by a textView in a layout as the java code runs? 

A:

I'd recommend using a Timer. 
private Timer timer = new Timer();
private TimerTask timerTask;
timerTask = new TimerTask() {
  @Override
  public void run() {
    //refresh your textview
  }
};
timer.schedule(timerTask, 0, 10000);

You can cancel it using:
timer.cancel();

