Define String Plurals

suggest change

To differentiate between plural and singular strings, you can define a plural in your strings.xml file and list the different quantities, as shown in the example below:

<?xml version="1.0" encoding="utf-8"?>
<resources>  
    <plurals name="hello_people">
        <item quantity="one">Hello to %d person</item>
        <item quantity="other">Hello to %d people</item>
    </plurals>
</resources>

This definition can be accessed from Java code by using the getQuantityString() method of the Resources class, as shown in the following example:

getResources().getQuantityString(R.plurals.hello_people, 3, 3);

Here, the first parameter R.plurals.hello_people is the resource name. The second parameter (3 in this example) is used to pick the correct quantity string. The third parameter (also 3 in this example) is the format argument that will be used for substituting the format specifier %d.

Possible quantity values (listed in alphabetical order) are:

few
many
one
other
two
zero

It is important to note that not all locales support every denomination of quantity. For example, the Chinese language does not have a concept of one item. English does not have a zero item, as it is grammatically the same as other. Unsupported instances of quantity will be flagged by the IDE as Lint warnings, but won’t cause complication errors if they are used.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Resources:
* Define String Plurals

Table Of Contents
2 Gradle
5 Intent
8 Resources
17 Service
19 WebView
31 SQLite
35 Glide
37 Dialog
38 ACRA
44 Handler
53 Toast
63 Menu
65 Picasso
70 Volley
71 Widgets
78 Realm
90 Spinner
95 OkHttp
108 TextView
109 ListView
111 Loader
118 Xposed
119 Security
121 ImageView
123 Doze Mode
130 Drawables
131 Colors
134 Fresco
139 AdMob
145 Keyboard
146 Button
150 EditText
155 Vk SDK
163 ExoPlayer
169 XMPP
175 OpenCV
177 Threads
184 ORMLite
186 TabLayout
190 LruCache
192 Zip files
194 Fastlane
199 FileIO
202 Moshi
210 VideoView
216 Paint
218 ProGuard
226 CleverTap
228 ADB shell
229 Ping ICMP
230 AIDL
234 Context
240 JCodec
242 Okio
249 FuseView
254 Looper
261 Fastjson
263 Jackson
267 Smartcard