android save programmatically created views

前端 未结 2 1983
陌清茗
陌清茗 2021-01-22 08:49

I programmatically create a RelativeLayout with some other views inside it and add it to the parent which is defined in XML. But all the views (incl. the layout) that were creat

2条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-22 09:22

    I recommend you look into Activity.onSaveInstanceState(Bundle):

    The default implementation takes care of most of the UI per-instance state for you by calling onSaveInstanceState() on each view in the hierarchy that has an id, and by saving the id of the currently focused view (all of which is restored by the default implementation of onRestoreInstanceState()). If you override this method to save additional information not captured by each individual view, you will likely want to call through to the default implementation [ via super.onSaveInstanceState() and super.onRestoreInstanceState()], otherwise be prepared to save all of the state of each view yourself.

    https://developer.android.com/reference/android/app/Activity.html#onSaveInstanceState(android.os.Bundle)

    as well as my answer here:

    How can I assign an ID to a view programmatically?

提交回复
热议问题