0

I know android chooses the appropriate values folder according to the locale. But I want to choose it myself from code.

 <com.example.typefacetest.CustomTextView
        android:id="@+id/banglaTextView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        custom:banglaText="@string/hello_world"
        android:text="@string/hello_world"
         />

In my values-bn folder, I have the String literal named hello_world which is used for the attribute custom:banglaText. If I don't set the locale, android will not choose the values-bn folder. Now I want to extract the string from that folder programmatically. How to do so ?

Md. Arafat Al Mahmud
  • 3,124
  • 5
  • 35
  • 66

1 Answers1

0

You can use this: ResourceBundle or write something like this:

Configuration configuration = getResources().getConfiguration();
configuration.locale = new Locale("en");
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
Resources resources = new Resources(getAssets(), metrics, configuration);
String string = resources.getString(id);

In id you should put string's id from strings.xml.

Forin
  • 1,549
  • 2
  • 20
  • 44
  • I dont want to set the configuration.locale as this is not recommended. http://stackoverflow.com/questions/2900023/change-language-programatically-in-android – Md. Arafat Al Mahmud Jul 08 '14 at 09:31