您的位置:首页 > 移动开发 > Android开发

android Resources getString with format arguments

2015-02-16 13:19 267 查看
android的string资源可以存放一个format来供动态组合argument使用:

其实调用的就是String类的format罢了.

/**
* Return the string value associated with a particular resource ID,
* substituting the format arguments as defined in {@link java.util.Formatter}
* and {@link java.lang.String#format}. It will be stripped of any styled text
* information.
* {@more}
*
* @param id The desired resource identifier, as generated by the aapt
*           tool. This integer encodes the package, type, and resource
*           entry. The value 0 is an invalid identifier.
*
* @param formatArgs The format arguments that will be used for substitution.
*
* @throws NotFoundException Throws NotFoundException if the given ID does not exist.
*
* @return String The string data associated with the resource,
* stripped of styled text information.
*/
public String getString(int id, Object... formatArgs) throws NotFoundException {
String raw = getString(id);
return String.format(mConfiguration.locale, raw, formatArgs);
}


Context里也有一个getString(int id, Object... formatArgs), 调用的其实就是Resources的.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐