I don't know if using Threads is the practice for what I am trying to achieve so please feel free to amend the code where you wish.
I am trying to implement a feature in my app where a TextView
switches to 1 value and thereafter reverts back to the initial value every 5 seconds. I have implemented the following using on a thread:
layoutDate.setText(firstNumber);
Thread numberSwitch = new Thread() {
@Override
public void run() {
while(!isInterrupted()) {
try {
Thread.sleep(5000);
runOnUiThread(new Runnable () {
@Override
public void run() {
layoutDate.setText(secondNumber);
}
});
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
};
numberSwitch.start();
I have tried adding layoutDate.setText(firstNumber)
just after the runUiOnThread
and also after the nested run
but it still doesn't work as I want it to.
I want to achieve something like the following: