Hi I have a ListView inside a fragment. I'd like to restore the selected item when the Fragment is reloaded (e.g. due to a rotation). To that end, I'm using onResume to determine the position and item id of the previously selected item inside the newly rendered ListView, then calling myListView.PerformItemClick(calls, position, itemId)
There are two issues I'm facing though 1) my ItemClick event handler will get a View in the AdapterView.ItemClickEventArgs that isn't the "normal" view (when performing a normal click from within the application, e.View is the LinearLayout that I'm using for every ListViewItem (the layout that belongs to the item selected) and e.Parent is the ListView itself), instead it seems to be the ListView itelf (so e.View == e.Parent). So, when I then look for GUI elements within e.View, I'm finding the first LinearLayout that there is (so the first item in the ListView - and thus the first item in the list gets the action performed that I do upon selection.. not the item I actually selected) 2) If I do myListView.PerformItemClick immediately in onResume, I'm having timing issues - it seems that even though the view should have been created, something is still rendering as I'm unable to find the usual GUI elements from within e.View and the app then crashes. If I add a small delay before calling myListView.PerformItemClick (launch a background task, sleep 500ms, then run PerformItemClick on the UI thread), things do work out except for issue 1. If I can solve issue 1) then I can get back on track but I'd also like to figure out which event to hook into to launch my PerformItemClick - what do I have to wait for exactly to ensure that my ListView is up and running the way it should? Regards Stephan -- View this message in context: http://mono-for-android.1047100.n5.nabble.com/ListView-preserve-selection-state-tp5711708.html Sent from the Mono for Android mailing list archive at Nabble.com. _______________________________________________ Monodroid mailing list Monodroid@lists.ximian.com UNSUBSCRIBE INFORMATION: http://lists.ximian.com/mailman/listinfo/monodroid