can I programmatically change <string name="title_activity_quiz">QuizActivity</string>
and even more important, will it be updated in the action bar?
Asked
Active
Viewed 1,271 times
0

Philip
- 1,068
- 3
- 12
- 21
-
3Why you want to do that ? It cannot be done – Gaskoin Mar 16 '14 at 20:00
-
Consider using a string array, instead. – Phantômaxx Mar 16 '14 at 20:05
-
2Does this answer your question? [Change value of R.string programmatically](https://stackoverflow.com/questions/9674925/change-value-of-r-string-programmatically) – user985366 Oct 09 '22 at 00:45
2 Answers
3
strong text Programmatically change a resource string?
If you are asking for how to change String resource content (during runtime) - no you cannot do that. Resources are created once (defined in XML files) and no more.
Instead of you can easily create another String resource and switch between them whenever you want it:
getActionBar().setTitle(context.getResources().getString(R.id.secondString));

Simon Dorociak
- 33,374
- 10
- 68
- 106
-
1This is my class,`public static class PlaceholderFragment extends Fragment {` how can I refer to getActionBar()? – Philip Mar 16 '14 at 20:13
-
1Look at [this link](http://www.vogella.com/tutorials/AndroidActionBar/article.html). – Simon Dorociak Mar 16 '14 at 20:14
-
great thanks! I did it, but it tells me min sdk is 11, mine is 8. But I have the support libs.. – Philip Mar 16 '14 at 20:17
-
1
-
I have imported the appcompat_v7, and my activity extend ActionBarActivity – Philip Mar 16 '14 at 20:25
-
hey geralt :-) you seem to be very experienced. do you know whether you can give a bundle when a button is clicked? like when button 1 is clicked an int with value 1 is given to the listener? – Philip Mar 16 '14 at 22:51
2
Maybe you could have two string resources and change dynamically the title of the ActionBar with getActionBar().setTitle(getString(R.string.your_new_resource))
.

helenej
- 331
- 4
- 15