I have a few ListViews driven by custom Adapters (ArrayAdapter and CursorAdapter). In the getView() and bindView() functions of the adapters, I’m creating a row in the ListView and setting a Listener to a particular UI element in the row.
Currently, as the ListView rows are sent to the Recycler the listener is still hooked up so the memory is never released. I don’t see a callback for when the row is being disposed of that would give me an opportunity to detach the listener before the row is recycled.
How do I manage the listener in the ListView rows? I only have the getView()/bindView() to add the listener to the row, but nothing to remove them.
Thanks
After some playing around I decided to use a ViewHolder pattern, and within that I have a variable that tracks the listener. When the recycled view is provided (where applicable) I pull out the listener (it does still exist) and make sure to unregister it as a listener, before creating a new listener and registering that in its place. This probably doesn’t catch EVERY listener, but I’m OK with a few ListView rows being stuck in memory.