Given my xml file below, I want to show the ListView when my object list is not empty and I want to show the ViewStub when my list is empty. I can get this to work, but whenever I change screen orientations, I lose the new data that I’ve added to my list.
Basically, any time I add a new object, I call my adapter’s changeData() method which changes the object list and calls the method notifyDataSetChanged(). Any advice on how to make sure this change persists across all views?
(There’s more in the XML but it’s irrelevant):
<ListView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_weight="1"
android:id="@android:id/list"></ListView>
<ViewStub android:id="@android:id/empty"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:layout="@layout/empty" />
</FrameLayout>
You have to maintain your screen state by using the savedInstanceState
Bundlewhich is available in theonCreate()method.Every time when you change your screen orientation
onCreate()is called.here an example : [CLICK]