I have a listview (with a custom list adapter), I need to display a countdown on every row.
For example, if my list contains 4 items, I will have 4 rows. At this point, I need to handle 4 different countdowns (one for each row) because time is different.
So far, I'm handling it the following way : in the Custom List Adapter, inside getView() method I create a new CountDownTimer and display remaining time inside TextView.
But the problem is that it slows the activity a lot, I can't even scroll correctly in the worst cases (because each time a row is displayed, it creates a new CountDownTimer).
I searched a lot for a better solution, but no one was satisfying.
Is there a cleaner and smoother solution to handle multiple countdown timers inside a listView ?
Thanks
Instead of trying to show the remaining time for all, the idea is to update the remaining time for the items which are visible.
Please follow the following sample code and let me know :
MainActivity :
activity_main.xml :
list_item.xml
It might be late but this is recyclerView version using php and json based on excellent answer of @Eldhose M Babu. Hope to be helpful :)
Adapter.java
MainActivity.java
Model.java
activity_main.xml
content_main.xml
list.xml
and for url part you can do something kind of:
Please have a look on this Countdown Timer in listview android example.
Custom Adapter
Main Activity
Thanks
Adapter class:-
public class CountdownAdapter extends RecyclerView.Adapter { ArrayList mList; Context mContext;
}