My by far highest voted contribution to the SE universe is my answer to How to use Android quantity strings (plurals)?. I am glad to see it helps a lot of people.
Nevertheless I'm not really happy with the current state of my answer. While it does a good job of explaining what you have to do (essentially "pass the quantity variable twice"), it lacks the explanation why you have to do it, i.e. explaining the quantity
parameter of the getQuantityString
method. Adding this explanation would mean explaining the relation between the quantity
attribute in the XML resources and that quantity
parameter.
I've been tempted to edit the answer and provide that kind of context to it, teaching about this whole quantity
concept in general. But so far I've been reluctant, since the current state of the answer seems to be "good enough" according to the votes.
My considerations are these:
On one hand, the added context might help the reader to understand the underlying concept of "Quantity strings in Android" better. Understanding this would likely also help them to avoid the most common pitfall, namely assuming that an entry for quantity="zero"
in the resources would be displayed if the quantity value passed to getQuantityString
was 0. I think almost every programmer stumbles across this "oddness" sooner or later when working with Android quantity strings.
On the other hand, people might have found the question by googling the error message from the question, to which the added context has a very vague relation at best.
Furthermore, the context alone would also be a good answer to a completely different question "Why is quantity="zero"
never used?".
But then again, it's also common to search for "How to use" when trying to get started with a completely new topic. Finding this question, and having the answer cover the concept in a more holistic fashion (including special cases like "What if I have two quantities" from the comments) means they can learn everything I think they need to know to have a solid basic understanding of the whole topic at hand.
So I'm really unsure whether or not it's a good idea to edit the answer and put more information about the "plurals" concept in.
---
in Markdown), and add a section explaining the concept, maybe using a header (###
for<h3>
in Markdown) to announce the change in focus.