Android: View.setID(int id) programmatically - how to avoid ID conflicts?

前端 未结 15 2528
眼角桃花
眼角桃花 2020-11-21 22:53

I\'m adding TextViews programmatically in a for-loop and add them to an ArrayList.

How do I use TextView.setId(int id)? What Integer ID do I come up wit

15条回答
  •  梦谈多话
    2020-11-21 23:25

    According to View documentation

    The identifier does not have to be unique in this view's hierarchy. The identifier should be a positive number.

    So you can use any positive integer you like, but in this case there can be some views with equivalent id's. If you want to search for some view in hierarchy calling to setTag with some key objects may be handy.

提交回复
热议问题