使用这个玩意来进行动态替换,比如:
<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
但可惜大部分语言都不大支持这样单复数形式,所以只能英文中使用