Reputation: 8964
I would like to set a String resource to some default value, and call that from certain places in my application. If a user has logged in, I would like to display the user's name there.
How can I dynamically modify a string resource to add the currently logged in user's name?
Thanks.
Upvotes: 0
Views: 229
Reputation: 52966
You can't modify a resource. You can add two resources: one default and one with a place holder for the username and swith between those in your code. Something like:
<string name="user_not_loggedin">Not logged in.</string>
<string name="user_loggedin">Logged in as %s</string>
Upvotes: 0
Reputation: 234857
You can't modify resources dynamically. You can store the user's name in persistent store (e.g., shared preferences) and update the display in code.
Upvotes: 4
Reputation: 656
you set it to default values in the xml files as best I can tell as those are stable then you can do new StringBuffer(existing).apppend new stuff dot to string back to the string ref
Upvotes: 0