Android: VIEW.SETID (INTID) - How to avoid ID conflicts when programming?

Asked 2 years ago, Updated 2 years ago, 45 views

When coding, I put them in TextViews in for-loop and then put them in ArrayList.

How do I use TextView.setId(intid)? What integer should the ID number be to avoid colliding with other IDs?

android conflict view

2022-09-21 21:33

1 Answers

According to the View description.

The identifier does not need to be an independent value in the view system. The identifier must be a positive number.

So you can use an integer that has any positive value. But in this case, the views have the same id. When you want to find a specific view (when you want to call it in), it would be most convenient to use "setTag" and use it with the main object.


2022-09-21 21:33

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.