开发者

Defining Strings in res/values/string.xml?

开发者 https://www.devze.com 2023-01-31 08:44 出处:网络
What\'s the point of defining strings in xml at the res/values/string.xml directory? Is it more efficient than just defining the strings as constants within your classes? (e.g. Database table creation

What's the point of defining strings in xml at the res/values/string.xml directory? Is it more efficient than just defining the strings as constants within your classes? (e.g. Database table creation scripts, etc..)

Is it a matter of organiz开发者_C百科ation or is there some benefit in how Android handles these objects in memory?


  • So you can easily translate them into different languages.
  • So they're nicely organized and you have them all in one place.


You can easily translate your app if you use strings.xml. Just create a new folder with suffix like values-cs and put the xml with czech strings in it and the whole app will be translated to czech if you have set czech localization in your phone.


  • applications access them/compute them faster than normal strings
  • localization

The hello string is defined in the res/values/strings.xml file. This is the recommended practice for inserting strings to your application, because it makes the localization of your application to other languages graceful, without need to hard-code changes to the layout file.

  • language (computer) translation

For me the first point is the deal breaker, anything to make your app faster. (this is assumed from the countless hours of creating my own applications and being told using string.xml is best from an optimization point of view, plus, especially in a long listview, it does seem to load faster for me (droid A855) )

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号