Can i have 2 different views with same id in android

后端 未结 2 1014
后悔当初
后悔当初 2021-01-25 07:57

Is it right to have same Id for a TextView and a ImageView ? Since they belong to one entity I gave both of them same Id. If yes.. then how can I find these views by id separate

2条回答
  •  北海茫月
    2021-01-25 08:52

    You theoretically can but it's highly advised not to. Duplicate IDs within same layout since it will prevent finding view by ID (You will need to iterate over children or otherwise reference them), and cause collision/outright crash when those views will attempt to store/restore their savedInstanceState.

提交回复
热议问题