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

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

    You can set ID's you'll use later in R.id class using an xml resource file, and let Android SDK give them unique values during compile time.

     res/values/ids.xml
    

    
    
    
    

    To use it in the code:

    myEditTextView.setId(R.id.my_edit_text_1);
    

提交回复
热议问题