Reputation: 623
I have a list view, which is showing multiple details with a edit text and count down timer text view.
For count down timer if i run a thread every 1000ms and subtract the time by 1000ms in the adapter data and do notify data set changed. It updates the timer data perfectly, but edit text state also gets updated which means as soon as user tried to write something focus gets cleared and value is also getting changed in the edit text.
Can anyone help with this problem ?
Thank you so much in advance.
Upvotes: 2
Views: 945
Reputation: 1457
You can make use of the CountDownTimer
class like this:
CountDownTimer cdt = new CountDownTimer(60000, 1000) {
public void onTick(long millisUntilFinished) {
TextView tv = (TextView) findViewById(R.id.tv);
tv.setText("Time left: " + millisUntilFinished / 1000 + " seconds" );
}
public void onFinish() {
TextView tv = (TextView) findViewById(R.id.tv);
tv.setText("Time up!");
}
}.start();
The above piece of code will start a countdown timer for 60 seconds and update the countdown text after every 1 second.
Upvotes: 3