• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps 2 DIMENSIONAL array help needed

amar77

Lurker
hi,

I am stuck with array stuff. I want to store about 400 records in 2 dimensional array. Its like,

ques[1][1] = this is the question
ques[1][2] = this the correct answer
ques[1][3] = option one
ques[1][4] = option two

ques[2][1] = this is the question
ques[2][2] = this the correct answer
ques[2][3] = option one
ques[2][4] = option two

Its easy to achieve this via java code. I want to store these in the resources xml files. I tried string-array but its only one dimensional..

Please help me to do this !! and please tell me how I can access this array according to index number..

thanks a lot :)
 
Technically, your example illustrates what is essentially an array of string arrays, so you should be able to just create two string arrays as an XML resource. E.g.,

Code:
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string-array name="questions">
        <item>"Question 1"</item>
        <item>"Question 2"</item>
        <item>"Question 3"</item>
        <item>"Question 4"</item>
    </string-array>
    
    <string-array name="answers">
        <item>"Dogs"</item>
        <item>"Cats"</item>
        <item>"Birds"</item>
        <item>"Fish"</item>
    </string-array>
</resources>

Then grab both string arrays using Resources. You could optionally store both arrays in an array of string arrays, but I think your code would end up being more readable if you didn't do that. Hopefully that helps you.
 
thanks a lot for the reply Nil :)

Is there any way to access the arrays by using index numbers? like question[3], answer[3] ??

regards
 
Back
Top Bottom