How to put a view in a bunch

I add dynamically created EditTexts to the layout (onClick button method). When I rotate the screen, the added edittexts disappear. How to add them to a package to put them in the onSavedInstanceState method? Or is there another way to do this? I know I can save text, but is there a way to save the layout of the screen 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 a fake proof of my application :)).

Thanks in advance!

+7
source share
4 answers

You cannot add views to a set because they are not detailed / serializable. The only thing you can and should save in the kit is the current state of activity.

You can save a list data structure or a counter variable that tracks dynamically generated views. Also save the string values โ€‹โ€‹of EditTexts. In onCreate, you must interpret this information to recreate the views and their states.

+9
source

You cannot save the submission. bundle is just the name of the pair. Of course, you can save the text and then display it again. as you said.

onsaveInsatnceState (batch save) saves the text as save.putString ('text1', 'bla bla'), of course you need a loop to save all your edittext.

then oncreated (package addition)

you can get what you added save.getString ('text1')

+1
source

Submissions themselves do not constitute information that must be retained. Instead, you should save your coordinates, width, height, value, etc.

0
source

Your data can be stored in a class or in an arraylist. when fragment activity is restarted, than you retrieve data from saveinstance state in oncreate function.

Use this function setRetainInstance (true). after using the function of the object, the activity of your fragment will not destroy.

0
source

All Articles