坏丫头音译歌词,Panoz Abruzzi,祥仔av视觉影院
android在设计view类时,为了能储存一些辅助信息,设计一个一个settag/gettag的方法。这让我想起在winform设计中每个control同样存在一个tag。
今天要说的是我最近学习android遇见的settag的坑。一般情况下我们只需要使用唯一参数的settag方法。但有时我们需要存储多个数据,所以这个时候我们就需要使用带key的重载。
文档是描述:“ the specified key should be an id declared in the resources of the application to ensure it is unique (see the id resource type). keys identified as belonging to the android framework or not associated with any package will cause an illegalargumentexceptionto be thrown.”
这里说明必须保证key的唯一,但是如果我们使用java常量定义key(private static final int tag_id = 1;)这样你任然会遇见如下错误:
java.lang.illegalargumentexception: the key must be an application-specific resource id
正确的解决方案是:
在res/values/strings.xml中定义这个key常量,如下:
<resources> <item type="id" name="tag_first"></item> <item type="id" name="tag_second"></item> </resources>
使用如下:
imageview.settag(r.id.tag_first, "hello"); imageview.settag(r.id.tag_second, "success");
以上就是对android settag方法的key问题的解决办法,谢谢大家对本站的支持!
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Android Manifest中meta-data扩展元素数据的配置与获取方式
Android实现获取meta-data和build.gradle的值
Android获取清单文件中的meta-data,解决碰到数值为null的问题
解决webview 第二次调用loadUrl页面不刷新的问题
解决Android WebView拦截url,视频播放加载失败的问题
Android webview加载https链接错误或无响应的解决
网友评论