0

I am facing an issue with "string.format" in android application. In my application when the user changes his language preferences from default (english) to any other foreign language (japanese,german etc) the variable string positioning is giving a force close error. Please refer the code below:

temp = String.format(locale,getResources().getString(R.string.temp_string), value, name);

where, temp_string = "The parcel number %1$d belongs to %2$s" for default selection (english) when other languages are selected in some of them %2$s comes before %1$d . Due to which the the application force closes. Is there a way around to dynamically handle the variable strings(value,name).

1 Answer 1

1

I'd do something like:

temp = getResources().getString(R.string.temp_string, value, name);

As you see, getString() method can also receive parameters to format. Then, place different strings resources on different folders. For instance:

res/
   values/
       string.xml <--- here you put "The parcel number %1$d belongs to %2$s"
   values-de/
       string.xml <--- here you put "The parcel number %2$d belongs to %1$s"

I'm just giving you an example; I actually do not know how germany order is. I just want to explain what you actually have to try.

Sign up to request clarification or add additional context in comments.

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.