Raj
Raj

Reputation: 15

How to change multiple language for Android App?

I am trying to change the language for my android app, however I could not do it.

I used string.xml to add my text and called it in my text views in my activities.

However, I have so many text Views.

I need to create as many string names or is there any possibilty to change if i add some text views.

I have so many textViews and also so many activities.

Please guide me.

I used string.xml to add my text and called it in my text views in my activities.

Upvotes: 1

Views: 176

Answers (1)

elyar abad
elyar abad

Reputation: 788

One way could be using sharedPrefrences, (specially in case of only two languages);

  1. Create your source of Strings in both languages. Do it anyway you like.

  2. Create the UI which user will use it to change the language. By this View you should change the value of the respected sharedPreference. The values would be "languageOne" and "languageTwo", or booleans.

  3. In all textViews, editTexts, and etc set the text like this: view.setText(sharedPreferenceValue.equals("languageOne")?"theStringInLanguageOne":"theStringInLanguageTwo");

Upvotes: 1

Related Questions