Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android ListFragment list view overlapping on orientation change

I'm using ListFragment and implementing LoaderManager.LoaderCallbacks from Android compatibility package for showing a list view in the app. The list is showing fine but when orientation changes, the list view is not proper (I think the view is overlapping on the previous one)

Picture here: list-view-after-orientation-change

Has anyone faced the same issue before? Could you let me know what might have been the issue or if any more details need to be provided.

like image 589
Gautham Avatar asked Jun 26 '12 14:06

Gautham


1 Answers

I found the error. It is due to creating list fragment every time when the activity is created, even if due to config change. But by default, android retains the fragment during the recreation of the activity during config changes.

Doing this solved my problem. Create fragment only if savedInstanceState is null.

if(savedInstanceState == null) {
// Initialize fragment here.
}
like image 55
Gautham Avatar answered Oct 12 '22 13:10

Gautham