2 DIMENSIONAL array help needed


Last Updated:

  1. amar77

    amar77 New Member This Topic's Starter

    Joined:
    Jul 27, 2010
    Messages:
    4
    Likes Received:
    0
    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 :)
     

    Advertisement
  2. Nil

    Nil Member

    Joined:
    Jul 26, 2010
    Messages:
    15
    Likes Received:
    3
    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 (Text):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <resources>
    3.     <string-array name="questions">
    4.         <item>"Question 1"</item>
    5.         <item>"Question 2"</item>
    6.         <item>"Question 3"</item>
    7.         <item>"Question 4"</item>
    8.     </string-array>
    9.    
    10.     <string-array name="answers">
    11.         <item>"Dogs"</item>
    12.         <item>"Cats"</item>
    13.         <item>"Birds"</item>
    14.         <item>"Fish"</item>
    15.     </string-array>
    16. </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.
     
    amar77 likes this.
  3. amar77

    amar77 New Member This Topic's Starter

    Joined:
    Jul 27, 2010
    Messages:
    4
    Likes Received:
    0
    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
     
  4. Nil

    Nil Member

    Joined:
    Jul 26, 2010
    Messages:
    15
    Likes Received:
    3
    If you get the string array using the Resources class, yes.
     
    amar77 likes this.

Share This Page

Loading...