0

my app has two languages. i translated all the strings of the string file but I have four small texts on the onboarding/walkthrough activity java as a string array. the question is how can I store them in the string file and call them from java activity?

public SliderAdapter(Context context){
    this.context = context;

}
public int[] slide_images = {
        R.drawable.a1,
        R.drawable.a2,
        R.drawable.a3,
        R.drawable.a4
};
public String[] slide_headers = {
        "txt1",
        "txt2",
        "txt3",
        "txt4"
};
public String[] slide_desc = {
        "body1",
        "body2,
        "body3",
        "body4"
};

1 Answers1

1

You can create a string array ressource: Doc on developer.android.com

In your example:

XML:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string-array name="slide_headers">
        <item>txt1</item>
        <item>txt2</item>
        <item>txt3</item>
        <item>txt4</item>
    </string-array>
</resources>

JAVA:

Resources res = getResources();
String[] slide_headers = res.getStringArray(R.array.slide_headers);

Do same things to slide_desc.

You can translate your array-string xml file with the same way you translate your string xml file.

Yannis Sauzeau
  • 396
  • 1
  • 11