0
<resources>
    <string name="app_name">UnConv</string>
    <string-array name="mainunit">
        <item>Area</item>
        <item>Pressure</item>
        <item>Speed</item>
        <item>Volume</item>
    </string-array>
</resources>

i want to add some other values to the above items like a subgroup. Example for area i want yard, acre etc how can i achieve that?

1 Answer 1

1

Unfortunately, There is no direct way to save two dimensional string-array in Android resource file. I provide 2 methods for replacement.

1. Save the data as Json string showing in the following code:

<string name="mainunit">{&quot;Area&quot;:[&quot;yard&quot;,&quot;acre&quot;],&quot;Pressure&quot;:[],&quot;Speed&quot;:[],&quot;Volume&quot;:[]}</string>

Then parse Json String to Java/Kotlin Object.

2. Save subgroup value splitting with ",", and get value by position, but it has drawback because it ignored the key name.

<string-array name="mainunit">
        <item>yard,acre</item>
        <item>Pressure</item>
        <item>Speed</item>
        <item>Volume</item>
</string-array>
Sign up to request clarification or add additional context in comments.

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.