1

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

Armling
  • 11
  • 1
  • what are the conditions? Did you check if the condition1 or condition2 are at any time true? – mthandr Jan 25 '15 at 20:05
  • yes of course. in fact, i forced it to enter the conditions by setting to value true. BTW, I am complete newbie to android, so if there is any mistake in my approach, let me know. – Armling Jan 25 '15 at 20:58

0 Answers0