How to put a View into Bundle

后端 未结 4 2465
梦毁少年i
梦毁少年i 2021-02-20 11:59

I\'m adding dynamically created EditTexts to a layout (onClick button method). When I rotate the screen the added edittexts disappear. How can I add them to a bundle to put them

4条回答
  •  旧巷少年郎
    2021-02-20 12:09

    You cannot add views to a bundle because they are not parcelable / serializable. The only stuff you can and should save into the bundle is the current state of the activity.

    You could maintain a list data structure or a counter variable that keeps track of the dynamically created views. Also save the string values of the EditTexts. In onCreate you should interpret that information in order to recreate the views and their states.

提交回复
热议问题