문제

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.

도움이 되었습니까?

해결책

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/

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top