Issue
I am trying to get Formatting String in AndroidViewModel by using following extension function but failed:
<string name="version_text">Version %1$s</string>
val versionText = getString(R.string.version_text, "1.0.0")
fun AndroidViewModel.getString(resId: Int, vararg formatArgs: Any) = (getApplication() as Context).getString(resId, formatArgs)
Result:
Version [Ljava.lang.Object;@bad21e0
Solution
vararg parameters are Array types. Use the * operator to expand them:
(getApplication() as Context).getString(resId, *formatArgs)
Answered By - Ben P.
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.