首页 > 解决方案 > 如何在 Android 数量字符串(复数)中使用零数量大小写?

问题描述

我正在尝试使用该getQuantityString方法在我的 Kotlin 应用程序中 根据 android 开发人员指南Resources进行检索。情况正常,但无法正常工作。这是我的代码。Quantity StringsQuantity StringOneotherzero

// text
txtNewProfileCount.text = resources.getQuantityString(
            R.plurals.shortlists_profile_count,
            filteredCandidateVMList.size,
            filteredCandidateVMList.size
        )

// plurals code
<plurals name="shortlists_profile_count">
    <item quantity="zero">Sorry, there are no new profiles in your various shortlists</item>
    <item quantity="one">Please review the new profile in your various shortlists</item>
    <item quantity="other">Please review the %1$d new profiles in your various shortlists</item>
</plurals>

如果数量是oneother,则结果是正确的。但在这种zero情况下,结果是Please review the 0 new profiles in your various shortlists。这不是我想要的结果。量大时如何解决zero

标签: androidkotlin

解决方案


zero案例从未在英语中使用过。英语仅使用oneand other。复数资源仅适用于特定语言的语法独特结构。这在文档中进行了解释:

选择使用哪个字符串完全基于语法必要性。在英语中,即使数量为 0,0 的字符串也会被忽略,因为 0 在语法上与 2 或除 1 之外的任何其他数字没有区别(“零书”、“一本书”、“两本书”等上)。

if因此,您必须使用代码中的语句手动选择单独的字符串资源。


推荐阅读