sundeep
sundeep

Reputation: 601

Android - change the language in Android Application not working

I am trying to do localization to my android application. The error message is not changed unless i force stop the app and start it after the language is changed.

public interface ApplicationConstants {

Resources res = MyActivity.getInstance().getAppContext().getResources();
public static final String NETWORK_ERROR_MESS=res.getString(R.string.str_network_error);
public static final String AUTH_ERR=res.getString(R.string.str_auth_error);

 }

In res-> values folder

Strings.xml

 <string name="str_network_error"> Network Error english.</string>
<string name="str_auth_error">Authentication failure english.</string>

In res-> values-fr folder

Strings.xml

 <string name="str_network_error"> Network Error france.</string>
<string name="str_auth_error">Authentication failure france.</string>

Upvotes: 0

Views: 1520

Answers (2)

Dima
Dima

Reputation: 1510

IMHO, all your problems appears due incorrect use of interfaces.
For more information read this answer

Upvotes: 0

M D
M D

Reputation: 47807

Try this way: when your main activity load

Locale locale = new Locale("fr");
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config,
getBaseContext().getResources().getDisplayMetrics());

And get the String in your activity like

String NETWORK_ERROR_MESS=youractivity.this.getString(R.string.str_network_error);
String AUTH_ERR=youractivity.this.getString(R.string.str_auth_error);

Upvotes: 1

Related Questions