i have a issue with my Listview, i want to set a countdown timer to all ListView\'s items, and i allready have googled a solution for this, but it isn\'t work correctly. The
I solved this differently in my case. Instead of having a timer handler set inside your getView(), I just set the time difference between the current time and your desired time to the TextView every time getView() is called. So move this code of yours back inside getView():
long outputTime = Math.abs(promoAction.timer_end
- System.currentTimeMillis());
Date date = new java.util.Date(outputTime);
String result = new SimpleDateFormat("hh:mm:ss").format(date);
tv.setText(result);
Then create a handler in the activity to call notifyDatasetChanged() every one minute on the listview's adapter:
Handler timerHandler = new Handler();
Runnable timerRunnable = new Runnable() {
@Override
public void run() {
myAdapter.notifyDataSetChanged();
timerHandler.postDelayed(this, 60000); //run every minute
}
};
I stop this handler on onPause():
@Override
protected void onPause() {
timerHandler.removeCallbacks(timerRunnable);
super.onPause();
}
And I start it again on onResume():
@Override
protected void onResume() {
timerHandler.postDelayed(timerRunnable, 500);
super.onResume();
}
And that's it. :)
Hope it helps.