I will be very grateful if someone can help me one this 🙂
I have a Custom Adapter (extending ArrayAdapter), and on the objects it displays (movieDatas), there is a property that vary with time (downloadProgress)
Since I use this adapter in multiple places, I wondered wether it is possible for my CustomAdapter to listen to every movieDatas.downloadProgress property, and then update itself ? Thus, not using ArrayAdapter.notifyDataSetChanged from the activity, but the adapter would take the decision to update by itself.
Previously, I used a Timer on every Activity that called myListView.invalidate() every 5 seconds, but I wondered if the adapter could handle the changes by itself ?
Thank you very much for your help, I begin in android development.
I don’t know how you’re doing it, but it sounds like you could totally use a callback to implement it.
1) Create an interface like this:
2) Add this to your MovieData object:
3) Override your custom adapter add method
4) Whenever an item gets modified, call
notifyDataSetChanged()on your adapter. You can even add it after thesuper.add(item)line in theaddimplementation, but this is extremely inefficient if you’re going to add a lot of items: Add them first then notify the changes.