Plural definition is ignored for zero quantity

后端 未结 3 618
慢半拍i
慢半拍i 2020-12-06 04:02

I use plurals to compile a quantity string for an Android application. I follow exactly what one can find in the tutorials:



        
3条回答
  •  有刺的猬
    2020-12-06 04:27

    In Kotlin (thanks to Dalmas):

    val result = commentsCount.takeIf { it != 0 }?.let {
        resources.getQuantityString(R.plurals.number_of_comments, it, it)
    } ?: resources.getString(R.string.number_of_comments_zero)
    

提交回复
热议问题