android - ListView with Coundown timer. Timer flickers when scrolling the listview -


in app, have show countdown timer every item in listview. have been able using countdowntimer. but, problem when scrolling listview or down, timer starts flickering. searched lot couldn't got solution.

my adapter class

public class buylistinglistadapter extends baseadapter  {  private context mcontext; private arraylist<vehicleattributes> mvehiclelist = new arraylist<vehicleattributes>(); private date currentdate; //saving position in map check if timer has been    //started row private hashmap<integer, boolean> timermap = new hashmap<integer, boolean>();  public buylistinglistadapter(context context,         arraylist<vehicleattributes> vehiclelist, boolean showgridview) {     this.mcontext = context;     this.mvehiclelist = vehiclelist;     this.showgridview = showgridview;     currentdate = new date(system.currenttimemillis());      int listsize = mvehiclelist.size();     (int = 0; < listsize; i++)         timermap.put(i, false); }  @override public int getcount() {     return mvehiclelist.size(); }  @override public object getitem(int position) {     return mvehiclelist.get(position); }  @override public long getitemid(int position) {     return 0; }  @override public view getview(final int position, view convertview, viewgroup parent) {     final viewholder holder;     if (convertview == null) {         layoutinflater inflater = layoutinflater.from(parent.getcontext());         convertview = inflater.inflate(r.layout.row_buy_listing_grid,                     parent, false);         holder = new viewholder();                     holder.timer_layout = (linearlayout) convertview                 .findviewbyid(r.id.timer_layout);                     holder.txt_remaining_days = (robotocondensedboldtextview) convertview                 .findviewbyid(r.id.txt_remaining_days);         holder.txt_remaining_hours = (robotocondensedboldtextview) convertview                 .findviewbyid(r.id.txt_remaining_hours);         holder.txt_remaining_mins = (robotocondensedboldtextview) convertview                 .findviewbyid(r.id.txt_remaining_mins);         holder.txt_remaining_secs = (robotocondensedboldtextview) convertview                 .findviewbyid(r.id.txt_remaining_secs);         holder.listing_status = (imageview) convertview                 .findviewbyid(r.id.listing_status);          convertview.settag(holder);     } else         holder = (viewholder) convertview.gettag();      final vehicleattributes vehicleattributes = mvehiclelist.get(position);      auctionmodel mauctionmodel = vehicleattributes.getauctiondetailmodel();     if (mauctionmodel != null) {         holder.img_auction.setvisibility(view.visible);          date auctionstartdate = util                 .getdatefromstring(mauctionmodel.getstarted_at(),                         "yyyy-mm-dd hh:mm:ss", "gmt");         date auctionenddate = util.getdatefromstring(                 mauctionmodel.getended_at(), "yyyy-mm-dd hh:mm:ss", "gmt");         long diff = currentdate.gettime() - auctionenddate.gettime();          if (diff < 0)             diff = -diff;         else             diff = 0;          if (timermap.get(position) == null || !timermap.get(position)) {              timermap.put(position, true);             mycountdown countdown = new mycountdown(position, diff, 1000,                     holder.txt_remaining_days, holder.txt_remaining_hours,                     holder.txt_remaining_mins, holder.txt_remaining_secs);             countdown.start();         }     }      return convertview; }  private class mycountdown extends countdowntimer {     robotocondensedboldtextview txt_remaining_days;     robotocondensedboldtextview txt_remaining_hours;     robotocondensedboldtextview txt_remaining_mins;     robotocondensedboldtextview txt_remaining_secs;     int position;      public mycountdown(int position, long millisinfuture, long countdowninterval,             robotocondensedboldtextview txt_remaining_days,             robotocondensedboldtextview txt_remaining_hours,             robotocondensedboldtextview txt_remaining_mins,             robotocondensedboldtextview txt_remaining_secs) {         super(millisinfuture, countdowninterval);         this.position = position;         this.txt_remaining_days = txt_remaining_days;         this.txt_remaining_hours = txt_remaining_hours;         this.txt_remaining_mins = txt_remaining_mins;         this.txt_remaining_secs = txt_remaining_secs;     }      @override     public void onfinish() {      }      @override     public void ontick(long millisuntilfinished) {         updatetimerlabel(position, millisuntilfinished, txt_remaining_days,                 txt_remaining_hours, txt_remaining_mins, txt_remaining_secs);     } }  private void updatetimerlabel(int position, long millis,         robotocondensedboldtextview txt_remaining_days,         robotocondensedboldtextview txt_remaining_hours,         robotocondensedboldtextview txt_remaining_mins,         robotocondensedboldtextview txt_remaining_secs) {     string days = string.format("%02d",             timeunit.milliseconds.todays(millis));     string hours = string.format(             "%02d",             timeunit.milliseconds.tohours(millis)                     - timeunit.days.tohours(timeunit.milliseconds                             .todays(millis)));     string mins = string.format(             "%02d",             timeunit.milliseconds.tominutes(millis)                     - timeunit.hours.tominutes(timeunit.milliseconds                             .tohours(millis)));     string secs = string.format(             "%02d",             timeunit.milliseconds.toseconds(millis)                     - timeunit.minutes.toseconds(timeunit.milliseconds                             .tominutes(millis)));      txt_remaining_days.settext(days);     txt_remaining_hours.settext(hours);     txt_remaining_mins.settext(mins);     txt_remaining_secs.settext(secs); }  static class viewholder {     networkimageview mvehicleimage;     robotocondensedboldtextview txt_remaining_days, txt_remaining_hours,             txt_remaining_mins, txt_remaining_secs;     linearlayout timer_layout; } } 

update

i updated answer here have look: (it's uses cardview recyclerview same principle can applied listview) how change text based on time , date?

you have take care when create countdowntimer instance , when cancel it. if don't cancel timer update wrong views.


Comments

Popular posts from this blog

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -