Frage

I am new to Android development and have been investigating the activity/fragment lifecycle RE recreating views.

I have read in the documentation/tutorials that views in an activity/fragment will be recreated automatically if they have an id (can't find a link to this).

My question is, do views that are created programmatically require an id, even if we do not require the id for other purposes?

It is simple enough to use View.generateViewId() to assign Ids, but it would be nice if this was not necessary.

War es hilfreich?

Lösung

My question is, do views that are created programmatically require an id, even if we do not require the id for other purposes?

Short answer: No, they don't require an ID. The long answer is of course that it depends on what you're doing and what state you need to save.

This article actually covers the topic pretty thoroughly, so I'd recommend reading it if you haven't: http://www.charlesharley.com/2012/programming/views-saving-instance-state-in-android/

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top