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 in the onSavedInstanceState method? Or, is there another way to do this? I know I can save the text, but is there a way to keep the screen layout when I rotate it? If the user presses the button and adds five EditTexts(with or without typing anything) I need to save this layout when the screen is rotated (I basically need to dummy-proof my app 🙂 ).
Thanks in advance!
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.