Cannot resolve string supplied to vararg parameter in extension function

后端 未结 2 1245
遇见更好的自我
遇见更好的自我 2021-01-02 08:26

strings.xml

Showing your number: %1$s

ActivityExt.kt

2条回答
  •  有刺的猬
    2021-01-02 09:31

    You should use the spread operator to pass in the varargs to the getString function:

    val text = getString(textResId, *formatArgs)
    

    This is because the type of formatArgs inside the showToast function is Array (there's no vararg type or anything like that), and if you pass that in without the *, you'll only pass a single parameter, which will be the array instead of its contents.

提交回复
热议问题