I have a TextView widget defined in XML but I want to programatically set a particular string in a language decided at runtime. I tried with the following code snippet but it does not work. It displays a blank text. Only the default english text works correctly.
PS: I assume these language fonts are already available because, when I hardcode a static string in an XML resource file in these languages, it displays correctly.
tv = (TextView) row.findViewById(R.id.myTextWid);
if (condition1) {
Locale loc = new Locale("ta", "IN");
tv.setTextLocale(loc);
tv.setText("என் தமிழ் உரை"); // my tamil text
} else if (condition2) {
Locale loc = new Locale("hi", "IN");
tv.setTextLocale(loc);
tv.setText("मेरी हिंदी पाठ"); // my hindi text
} else {
tv.setText("My default english text");
}
Using Android Studio 1.0.1; compiling with API 21; min sdk API 15