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

前端 未结 15 2716
眼角桃花
眼角桃花 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:36

    In order to dynamically generate View Id form API 17 use

    generateViewId()

    Which will generate a value suitable for use in setId(int). This value will not collide with ID values generated at build time by aapt for R.id.

提交回复
热议问题