Android: Dealing with Multi-Select ListViews and Updating

0 Flares Twitter 0 Facebook 0 StumbleUpon 0 Google+ 0 LinkedIn 0 0 Flares ×

On my current Android project I found a problem whereby I was updating the contents of my listview, and expecting it to remember which items were checked. It turns out however that I was wrong!

The Android listview maintains its knowledge of which items are checked by simple index position – so if you update the items in the listvoew and call notifyDataSetChanged on your adapter, you can get some strange behavior. In my case the solution was simple – get the selected items before the change, restore the selected items after the change:

And my getSelectedObjects function:

And once again my sanity is restored!

,

The Essential App Marketing Kit
Subscribe To My Newsletter To Get an Entire Chapter From The Book for FREE
Never display this again
0 Flares Twitter 0 Facebook 0 StumbleUpon 0 Google+ 0 LinkedIn 0 0 Flares ×