android 动态获取ID通过Resources的 getIdentifier 方法
Posted ihrthk
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了android 动态获取ID通过Resources的 getIdentifier 方法相关的知识,希望对你有一定的参考价值。
public int getIdentifier (String name, String defType, String defPackage)
Added in API level 1Return a resource identifier for the given resource name. A fully qualified resource name is of the form "package:type/entry". The first two components (package and type) are optional if defType and defPackage, respectively, are specified here.
Note: use of this function is discouraged. It is much more efficient to retrieve resources by identifier than by name.
Parameters
name | The name of the desired resource. |
---|---|
defType | Optional default resource type to find, if "type/" is not included in the name. Can be null to require an explicit type. |
defPackage | Optional default package to find, if "package:" is not included in the name. Can be null to require an explicit package. |
Returns
- int The associated resource identifier. Returns 0 if no such resource was found. (0 is not a valid resource ID.)
以上是关于android 动态获取ID通过Resources的 getIdentifier 方法的主要内容,如果未能解决你的问题,请参考以下文章
Android - 通过 ID 从动态 EditTexts 获取数据
android.content.res.Resources$NotFoundException: Main 中的字符串资源 ID 致命异常
从 Resources 对象中检索所有 Drawable 资源
android.content.res.Resources$NotFoundException:资源 ID #0xffffffff