Is there a way to change the text in the TextView when running java code?

I have a TextView in XML layout (in android app). This TextView displays the string value in the strings.xml file. However, since my java code is working, I want the value of this line to change every second for 4 consecutive seconds, and I want the XML layout to reflect this change.

Is there a way to change the string value in the strings.xml file when running java code? If there is no alternative way to change the text displayed by the textView in the layout when the java code is executed?

+3


source to share


1 answer


I would recommend using 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 reverse it using:

timer.cancel();

      

+3


source







All Articles