Manufacturing Unique R.id Values(转)
来源:互联网 发布:手机农村淘宝 编辑:程序博客网 时间:2024/05/01 18:29
Manufacturing Unique R.id Values
If you have been developing in Android for any length of time, you’ll most likely be aware that one of the most useful portions the resource framework is the fact that Views and other resources can be given an android:id tag in their XML declaration, and Android will make sure to compile all the ids into unique integer values that can be accessed from Java code by calling R.id.. This allows us to reduce the number of event listeners an application requires because it can uniquely identify the view that triggered the event by matching its id. And, of course, we prefer using integer ids for this as opposed to matching Objects or String tags because the ids fit nicely into switch statements!
For example, a layout with two buttons, both pointing at the same action method:
We can determine which button was pressed in the Activity by checking the sender’s id:
This is not breaking new, and is just one of many useful properties of android:id…
But what if we didn’t use XML to create our layouts/menus/etc.? What if we created a series of Views in Java code? Are we destined to go wanting without the assistance of the unique R.id generator? Certainly not!
Making id Elements Yourself
To reserve a set of ids for your own use in application, simply create an ids.xml file in the res/values directory of your project. The syntax coupled with creating this file is pretty self-explanatory
res/values/ids.xml
Now let’s take these fresh ids and add them to a series Buttons created in a dynamic layout:
That’s it! Just another practical application of a little known resource type in the Android framework.
Note: you can access this website: http://wiresareobsolete.com/wordpress/2011/04/manufacturing-ids/
- Manufacturing Unique R.id Values(转)
- MySQL中详细update (on duplicate key update id=values(id),value=values(value)......) (转)
- Android Unique Device ID
- Unique ID策略
- arduino: read unique ID
- STM32F0唯一ID ,Unique device ID ,UID
- STM32 Unique device ID reading
- 读取STM8 Unique ID registers
- 生成唯一序列号 Unique ID
- stm32 unique device id (UDID)
- R.layout..、R.id...与R.drawable...
- 关于 R.id.
- 关于R和id
- android-R.id
- java.lang.IllegalArgumentException: id values error, need 2 id value
- MySQL中详细update (on duplicate key update id=values(id),value=values(value)......)
- Arcgis分级时出现Too many unique values (> 65536).
- 哭笑不得的找不到id-R.id.
- 数据库类
- 【转】flex自定义皮肤
- JavaScript的9个陷阱及评点
- acceptsFirstMouse
- 每天学习一算法系列(7) (根据上排给出十个数,在其下排填出对应的十个数)
- Manufacturing Unique R.id Values(转)
- ORACLE索引与高性能SQL介绍
- 缩略图,水印
- dede关键词维护自动加内链锚文本
- 文件上传类
- 分布式数据库教案
- gentoo镜像服务器切换
- 分页类
- Struts2.1 annotation防止表单重复提交