简体   繁体   中英

How to display textview dynamic value for localization of android

Hello friends I want to integrate multiple languages in my application so I made multiple values folder for different languages. Now my question is how can I display my dynamic textview value which comes from my web api which is string value. But How can I display language as per my choice from application. Below I have mentioned my code. Please help me. Thanks!

Main.java

TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.fragment_main);
   textView=(TextView)findViewById(R.id.textView1);
    textView.setText("My custom text which comes from web api");

   }

You can use dynamic value in TextView with localization in resource folder. You can localize text by with country code and language code. like:

res/values-en/string.xml
res/values-hi/string.xml
res/values-IN-gu/string.xml

Read More

You can achieve the language localisation from the android framework using strings.xml, create one strings.xml for each language inside the proper values folder. Refer this LINK to do this.

From server you can get the text key which you define in stings.xml then in your textview set this key and android will automagically show the proper localised text.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM