Dynamically Set ID to a Button in Android

点点圈 提交于 2019-12-05 21:58:20

In your res/values folder you can keep an ids.xml file, where you can define:

<resources>
   <item type="id" name="your_button_id"/>
   ...
</resources>

Then, you can use it in your code:

changeButton.setId(R.id.your_button_id);

If your goal is to track it, you could try setTag:

 changeButton.setTag("any_tag");

Notice that the tag is of type Object, meaning it could be any object you want (String, int, Date, CustomeObject, ...etc).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!