In an Android app, I need to select resources from a resources folder other than the currently selected one (the interface language is whatever the system selects, but the user may select a different language for TTS). Due to the way the application is structured, switching resources is not an option; I need both the default and the alternate set at the same time. I was able to use this code to, for example, select Spanish strings when the user interface was in English:
class SpanishStrings()
{
private Resources mResources;
public Foo(Context context)
{
final Resources oldResources = context.getResources();
Configuration oldConfiguration = oldResources.getConfiguration();
DisplayMetrics metrics = oldResources.getDisplayMetrics();
Configuration configuration = new Configuration(oldConfiguration);
configuration.locale = new Locale("es", "es");
mResources = new Resources(oldResources.getAssets(), metrics, configuration);
}
String getString(int id)
{
return mResources.getString(id);
}
}
But this also set the entire user interface to Spanish! Can Android only have one active Resources at a time?
This is running on Android 2.3.4, if that makes any difference.