Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

Louis Sankey
Louis Sankey
22,595 Points

implement getter and setter methods for a countdown timer?

Hello Android experts, I have a list view and I am trying to setup a countdown timer in each list item. I want to be able to host the countdown timer in my model list item class, but then I have no idea how to get the countdown timer in my adapter and set the countdown textview with the countdown. I can call listItem.getCountdown(), but what does that do for me? Maybe I need another method in my model class that returns a string with the formatted countdown time, but then won't that be a static string and not update like a countdown timer would? I'm sure I'll be working on this all day so any help would be greatly appreciated. Thanks in advance.

2 Answers

Seth Kroger
Seth Kroger
56,413 Points

You haven't said how you are implementing the countdown timer but it would be a good idea for it to have a getRemainingTime() method. Because the display will be dynamic, you'll probably be updating it on an interval through notifyDatasetChanged() and call on it to set text field.

Louis Sankey
Louis Sankey
22,595 Points

yes, that is basically what I ended up doing. I made getRemainingTime() return long value and then re-instantiate whenever the view is recreated. Thanks for the help!