Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use Java/Android string formatting on <string-array>

How can is use string formatting on the
<string-array><item> - resource in Android?

Should i do it like in the following example(and how should i do it if yes)...

<string-array name="notification-msgs">
   <item>%s sent you a message.</item>
   <item>%s answered to your Story</item>
</string-array>

or what kind of technique is common to use in this case? I only know how to Format string resources.(with getString(R.id.mystring,replacevalue)) Thanks for any help!
EDIT:

  • I tried to use getStringArray(), but this method does not accept more then one argument, which just is an Array-Ressource.
like image 348
laim2003 Avatar asked Oct 17 '22 17:10

laim2003


1 Answers

Unfortunately there is no direct way provided by Android to achieve this. Best you can do is:

String.format(getResources().getStringArray(R.array.notification-msgs)[0], "Someone")

like image 65
Sagar Avatar answered Oct 20 '22 19:10

Sagar