21

Is there a way to do this? For instance, I have a setting in my preferences that can convert between metric and standard units of measurement and when the user changes this I would like to update a few strings to change some labels around within my app.

1
  • 1
    Please share your code.. As far as I have understood your question this is easily achievable. Commented Aug 4, 2011 at 6:05

2 Answers 2

26

You can update the label on TextView or anything similar.

  • Get the updated string using update_str = Context.getResources().getString (R.string.update_identifier)
  • Update the label using ((TextView)findViewById (R.id.textview)).setText (updated_str)
Sign up to request clarification or add additional context in comments.

Comments

9

You may use following instructions to fetch saved labels from strings.xml file and show them accordingly at some 'if statement' which could check your

pref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()) .getString("conversion_mode", "");

String string = getString(R.string.update_identifier);

or

getResources().getString (R.string.update_identifier)

would do the best

getString(int) or getText(int) may be used to retrieve a string. Please note getText(int) will retain any rich text styling applied to the string.

Find the Reference

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.