0

I want to use multi language in my app but cant solve problem with array; I couldn't define text from XML here. So what do you advise me to do here so that i can use multi language ? thanks a lot

public static final String[] columns = { "Bluetooth", "WiFi",
"Mobile Networks", "Auto Sync", "Gps", "Auto-rotate screen",
"Vibrate on touch", "Airplane mode", "Brightness", "Sleep",
"Volume Settings", "Phone Ringtone", "Uninstall",
"Backup & Restore", "Battery Usage", "Cache Clear", "System Clear",
"System Info" };
}
3
  • 1
    developer.android.com/guide/topics/resources/… Commented Mar 1, 2016 at 10:50
  • I try this but get that error = getResources unknown and advise to creat a new method Commented Mar 1, 2016 at 15:15
  • You can call getResresources() from any class that exteds from context (for example an Activity). if you are not in one, than pass the context to the class in the contructor like stackoverflow.com/questions/8238588/… Commented Mar 3, 2016 at 15:30

2 Answers 2

2

You can define string array in strings.xml, as the documentation says like:

<resources>
    ...
    <string-array name="numbers">
        <item>1</item>
        <item>2</item>
        <item>3</item>
        <item>4</item>
        <item>5</item>
        <item>6</item>
        <item>7</item>
        <item>8</item>
        <item>9</item>
        <item>10</item>
    </string-array>
    ...
</resources>

Than you can get it from code like :

String [] fiilliste = getResources().getStringArray(R.array.numbers); 

Don't forget to define your array in every strigns.xml in each of your values-XX folder which you want to support.

Sign up to request clarification or add additional context in comments.

1 Comment

You literally beat me to it by seconds! Only thing I would add is that if the those columns are for a database's columns this will break things, therefore there needs to be a better separation of concerns.
0

I think the best approach is to use R.string.whateveryouwant as Integer array, something like this:

Integer[] columns = { R.string.bluetooth, R.string.wifi, .... }

And when you display the text get the value from the language xml file, given the Integer key.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.