一般情况下,我们只需要使用唯一参数的setTag方法,给控件附加一些信息。但我们需要去附加多个信息的时候,开发就需要使用带key的重载。如果我们使用java常量定义key,就会遇见如下错误:
这是Google官方文档的描述:
“ 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.”
此时,我们需要在res/values/ids.xml中(也可以strings.xml中定义),定义这个key常量:
这样就可以正常使用了: