0

can I programmatically change <string name="title_activity_quiz">QuizActivity</string> and even more important, will it be updated in the action bar?

Philip
  • 1,068
  • 3
  • 12
  • 21

2 Answers2

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
  • 1
    This is my class,`public static class PlaceholderFragment extends Fragment {` how can I refer to getActionBar()? – Philip Mar 16 '14 at 20:13
  • 1
    Look 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
    @user3385402 yes, then you can call `getSupportActionBar()`. – Simon Dorociak Mar 16 '14 at 20:25
  • 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