getText 与getString 区别
2015-04-16 15:51
281 查看
Android提供多种获取资源文件方法,但是需要注意以下方法:
CharSequence getText(int resId):返回本地、样式化的字符。
String getString(int resId) :返回字符串
CharSequence getText(int resId):返回本地、样式化的字符。
String getString(int resId) :返回字符串
/** * Return the string value associated with a particular resource ID. The * returned object will be a String if this is a plain string; it will be * some other type of CharSequence if it is styled. * {@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. * * @throws NotFoundException Throws NotFoundException if the given ID does not exist. * * @return CharSequence The string data associated with the resource, plus * possibly styled text information. */ public CharSequence getText(int id) throws NotFoundException { CharSequence res = mAssets.getResourceText(id); if (res != null) { return res; } throw new NotFoundException("String resource ID #0x" + Integer.toHexString(id)); }
/** * Return the string value associated with a particular resource ID. 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. * * @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) throws NotFoundException { CharSequence res = getText(id); if (res != null) { return res.toString(); } throw new NotFoundException("String resource ID #0x" + Integer.toHexString(id)); }
相关文章推荐
- Dom4j中getText()和getStringValue()的作用和区别。
- Android getText(int resId) 与 getString(int resId)的区别
- CharSequence的getText()与String的getString()区别和为什么加""
- CharSequence的getText()与String的getString()区别
- Dom4j中getStringValue()和getText()用法和区别
- Dom4j中getStringValue()和getText()用法和区别
- 浅析 javax.servlet.ServletRequest 的getAttribute(String name)与getParmeter(String name)的区别
- ASP.NET中Get和Post的用法 Request.QueryString,Request.Form,Request.Params的区别 [转]
- ASP.NET中Get和Post的用法 Request.QueryString,Request.Form,Request.Params的区别
- [备忘]ASP.NET MVC中RouteData.GetRequiredString("key")方法和RouteData.DataTokens["key"]方法使用上的区别
- javax.servlet.ServletRequest 的getAttribute(String name)与getParmeter(String name)的区别
- obj.getClass().getName()==String.class.getName()和obj.getClass==String.class的区别
- Android getText(@string/a)和直接使用字符的区别
- ASP.NET中Get和Post的用法 Request.QueryString,Request.Form,Request.Params的区别 [转]
- ASP.NET中Get和Post的用法 Request.QueryString,Request.Form,Request.Params的区别 [转]
- request.getRequestURI(),request.getRequestURL(),request.getQueryString()区别
- 2014-12-03:hibernate get()与load()区别,json字符串转换为json对象,String与date相互转换
- JSON中optString()和getString()区别
- GetStoredProcCommand和GetSqlStringCommand的区别
- Android getText(int resId)和getString(int resId)