在Android中的字符串资源中,今天留意到一个很特别的东西,叫plurals,其实际的意思就是因为英文中有单,复数之分,所以有的时候,当涉及到数量时,可以在字符串资源中
使用这个玩意来进行动态替换,比如:

<xml version="1.0" encoding="utf-8"?>  
<resources>
<plurals name="numberOfCars">
<item quantity="one">%d car</item>
<item quantity="other">%d cars</item>
</plurals>
</resources>



   使用的时候:


// Get the number of cars  
int count = getNumberOfCars();
Resources res = getResources();

String cars = res.getQuantityString(R.plurals.numberOfCars, count, count);



  其中第2个参数是实际的个数,比如是通过程序计算出来的,第3个参数是对应使用哪一个复数形式,比如one car,two cars这样,还支持:


•zero


•one


•two


•few


•many


•other


  但可惜大部分语言都不大支持这样单复数形式,所以只能英文中使用