Im currently working with custom views which will be added to a layout dynamically. I understand how view states are safed and restored.
According to the documentation, only views with an id will be persisted by the system. So the suggested solution is to use View.getViewId()
in order to set an id to each dynamically added view.
The problem is, that on orientation change, each view which gets an id via this method, will get a different id than before the orientation change happened. This prevents the view state from being restored since the ids don't match up.
Easiest setup to try this: Add an EditText programmatically to an activity, give it an id with
View.generateViewId()
then enter some text and rotate.
Am I missing something? Is there no way to give ids to dynamically added views so that they restore themselves on orientation changes?