Search code examples
javaandroidlistviewandroid-2.3-gingerbread

Android 2.3 maintain ListView position when using Fragments


I have been trying to find a solution to this. How do I maintain the ListView position when I am using Fragments and someone rotates the device.

The rotation itself resets everything and it's back to 0 again. I can get it to work with the multiple examples when I am using normal Activities, but how do I do it when I am inside a specific Fragment?


Solution

  • Make sure that you do not call setAdapter() again on rotation or after any operation you do. Always call notifyDataSetChange() and your list will remain at the same point

    Other workaround can be that you save the position of the current list item and call setSelection(position) for what you want to keep