Good. Let them make the easy way. In the Layout folder, make 2 copies of the XML layouts. Name one of them main.xml (your local language), and the other mainen.xml for English. In the values ββfolder, the strings.xml file also contains two lines of text for both languages: <string name="hello">Tere, Maailm!</string> for the local language and <string name="hello_en">Hello World!</string> for English. Returning to the xml layouts, main.xml contains android:text="@string/hello" for your text, and the second duplicate mainen.xml contains all the same layouts and lines with a slight difference when receiving the English version of a line of text from the strings.xml file : android:text="@string/hello_en" . And programmatically, to set the title if necessary and indicate at the beginning of each action which layout to choose, use the languageToLoad global variable that was declared and created in your first (initial) class: protected static boolean languageToLoad = true; , in the same class, the onCreate method should contain several switches (you also need to define and name them in the corresponding xml format): '
// ... View radio1 = findViewById(R.id.Et); radio1.setOnClickListener(this); View radio2 = findViewById(R.id.En); radio2.setOnClickListener(this); // ...'
And then in the class:
// ... public void onClick(View v1) { switch (v1.getId()) { case R.id.Et: languageToLoad = true; break; case R.id.En: languageToLoad = false; break; // ...'
And later in the program, in the onCreate method of your various actions:
//... public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (YourSuperClass.languageToLoad) { setContentView(R.layout.youractivity); // estonian setTitle(R.string.youractivity_title); } else { setContentView(R.layout.youractivityen); // english setTitle(R.string.youractivity_title_en); } Intent i = getIntent(); //...'
source share