2 DIMENSIONAL array help needed

Discussion in 'Application Development' started by amar77, Jul 27, 2010.

  1. amar77

    amar77 New Member
    5

    Jul 27, 2010
    4
    0
    5
    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
    16

    Jul 26, 2010
    15
    3
    16
    Student :|
    Idaho, USA
    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
    5

    Jul 27, 2010
    4
    0
    5
    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
    16

    Jul 26, 2010
    15
    3
    16
    Student :|
    Idaho, USA
    If you get the string array using the Resources class, yes.
     
    amar77 likes this.

Share This Page

Loading...