androidandroid-layoutandroid-orientationonconfigurationchanged

Restoring state of TextView after screen rotation?


In my app I have TextView and EditText. Both have data in it. When the screen orientation changes the data in the EditText remains, but TextView data is cleared.

Can some one help me out to find a way to retain data in TextView too?


Solution

  • If you want to force your TextView to save its state you must add freezesText attribute:

    <TextView 
         ... 
         android:freezesText="true" />
    

    From documentation on freezesText :

    If set, the text view will include its current complete text inside of its frozen icicle in addition to meta-data such as the current cursor position. By default this is disabled; it can be useful when the contents of a text view is not stored in a persistent place such as a content provider