0

I'm using two different views in a fragment that contain a ListView. These ListViews use the same ListAdapter. In landscape, I show the listview in the fragment and in portrait, there is a button that shows a dialog containing the listview. My fragment is setRetainedState(true) and I don't recreate my listAdapter if it's not null.

I've set a selector for the background color of my ListItem, (if state_activated => red background; default => transparant). When initializing my ListView (on change to landscape and on displaying dialog with listview) I set the ChoiceMode to CHOICE_MODE_SINGLE.

This way, if I call 'view.setActvated(true)' in my OnItemClickListener of my ListView, the right item gets the right background, and everything works fine.

My next step was storing a reference of the activated view in my Adapter. In my getView() method I check if the view i'm building is the one I've stored. If so, I call 'convertView.setActivated(true)' and return the convertView. But when my ListView gets recreated with the same adapter, it does not set the correct view (or any other view) activated, even though setActivated(true) was called for 1 specific View (checked with Log.d)

I only get it right if I call 'view.setActivated(true)' in the OnItemClickListener

4

0 回答 0