HELP WITH Multidimensional arrays

Put your problem here if it does not fit any of the other categories.

HELP WITH Multidimensional arrays

Postby igorski88 » Sun Mar 06, 2011 2:40 am

Hello,
I am working with multidimensional arrays. The question is...
How do i set a multidimensional arrays in my Strings.xml file?

Im basically tying to avoid Creating 20 different String arrays in the strings.xml just to create one multidimensional array in my Java code :(
igorski88
Junior Developer
Junior Developer
 
Posts: 17
Joined: Sun Feb 27, 2011 9:03 pm

Top

Re: HELP WITH Multidimensional arrays

Postby raj_J2ME » Mon Mar 07, 2011 12:28 pm

igorski88 wrote:Hello,
I am working with multidimensional arrays. The question is...
How do i set a multidimensional arrays in my Strings.xml file?

Im basically tying to avoid Creating 20 different String arrays in the strings.xml just to create one multidimensional array in my Java code :(

Is this of any help?

Code: Select all
<books>
    <book pages="428" title="book1"/>
    <book pages="599" title="book2"/>
    <book pages="204" title="book3"/>
</books>

And the XPath expression:
Code: Select all
/books/book[@title='book1']/@pages
Thanks with Regards,
Raj - The Kernel
raj_J2ME
Master Developer
Master Developer
 
Posts: 311
Joined: Tue Feb 15, 2011 7:40 am
Location: The Capital of India,

Re: HELP WITH Multidimensional arrays

Postby igorski88 » Mon Mar 07, 2011 5:43 pm

Im not realy familier with this expression. the reason i needed it was becouse i had an expanable list. I needed the "child" to get filled with iformation accourding to a selection made previasly in the app. so what i did was make a bunch of one-dimensianal arrays and turned them into multidemensianal in my java code.
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. /** Called when the a pic is selected. */
  2.         gridview.setOnItemClickListener(new OnItemClickListener() {
  3.             public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
  4.                 Item_Selected = position ;
  5.                
  6.                
  7.                 /** Set info for Tan Belt */
  8.                   if(position == 0) {      
  9.                         SyllabusGroupBelt_Array = getResources().getStringArray(R.array.TanSyllabusGroup_Array);
  10.                         SyllabusChildBelt1_Array = getResources().getStringArray(R.array.TanSyllabusChild1_Array);
  11.                         SyllabusChildBelt2_Array = getResources().getStringArray(R.array.TanSyllabusChild2_Array);
  12.                         SyllabusChildBelt3_Array = getResources().getStringArray(R.array.TanSyllabusChild3_Array);
  13.                         SyllabusChildBelt4_Array = getResources().getStringArray(R.array.TanSyllabusChild4_Array);
  14.                         SyllabusChildBelt5_Array = getResources().getStringArray(R.array.TanSyllabusChild5_Array);
  15.                         SyllabusChildBelt6_Array = getResources().getStringArray(R.array.TanSyllabusChild6_Array);
  16.                         SyllabusChildBelt7_Array = getResources().getStringArray(R.array.TanSyllabusChild7_Array);
  17.                         SyllabusChildBelt8_Array = getResources().getStringArray(R.array.TanSyllabusChild8_Array);
  18.                         SyllabusChildBelt9_Array = getResources().getStringArray(R.array.TanSyllabusChild9_Array);
  19.                         SyllabusChildBelt10_Array = getResources().getStringArray(R.array.TanSyllabusChild10_Array);
  20.                         SyllabusChildBelt11_Array = getResources().getStringArray(R.array.TanSyllabusChild11_Array);
  21.                         SyllabusChildBelt12_Array = getResources().getStringArray(R.array.TanSyllabusChild12_Array);
  22.                         SyllabusChildBelt13_Array = getResources().getStringArray(R.array.TanSyllabusChild13_Array);
  23.                         SyllabusChildBelt14_Array = getResources().getStringArray(R.array.TanSyllabusChild14_Array);
  24.                        
  25.                   }
  26.                     /** Set info for Gray Belt */
  27.                   if(position == 1) {      
  28.                         SyllabusGroupBelt_Array = getResources().getStringArray(R.array.GraySyllabusGroup_Array);
  29.                         SyllabusChildBelt1_Array = getResources().getStringArray(R.array.GraySyllabusChild1_Array);
  30.                         SyllabusChildBelt2_Array = getResources().getStringArray(R.array.GraySyllabusChild2_Array);
  31.                         SyllabusChildBelt3_Array = getResources().getStringArray(R.array.GraySyllabusChild3_Array);
  32.                         SyllabusChildBelt4_Array = getResources().getStringArray(R.array.GraySyllabusChild4_Array);
  33.                         SyllabusChildBelt5_Array = getResources().getStringArray(R.array.GraySyllabusChild5_Array);
  34.                         SyllabusChildBelt6_Array = getResources().getStringArray(R.array.GraySyllabusChild6_Array);
  35.                         SyllabusChildBelt7_Array = getResources().getStringArray(R.array.GraySyllabusChild7_Array);
  36.                         SyllabusChildBelt8_Array = getResources().getStringArray(R.array.GraySyllabusChild8_Array);
  37.                         SyllabusChildBelt9_Array = getResources().getStringArray(R.array.GraySyllabusChild9_Array);
  38.                         SyllabusChildBelt10_Array = getResources().getStringArray(R.array.GraySyllabusChild10_Array);
  39.                         SyllabusChildBelt11_Array = getResources().getStringArray(R.array.GraySyllabusChild11_Array);
  40.                         SyllabusChildBelt12_Array = getResources().getStringArray(R.array.GraySyllabusChild12_Array);
  41.                         SyllabusChildBelt13_Array = getResources().getStringArray(R.array.GraySyllabusChild13_Array);
  42.                   }
Parsed in 0.042 seconds, using GeSHi 1.0.8.4


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class MyExpandableListAdapter extends BaseExpandableListAdapter {
  2.                 // data set. children[i] contains the children (String[]) for
  3.                 // groups[i].
  4.                 private String[] groups = MainActivity.SyllabusGroupBelt_Array;
  5.                 private String[][] children = {
  6.                          MainActivity.SyllabusChildBelt1_Array,
  7.                          MainActivity.SyllabusChildBelt2_Array,
  8.                          MainActivity.SyllabusChildBelt3_Array,
  9.                          MainActivity.SyllabusChildBelt4_Array,
  10.                          MainActivity.SyllabusChildBelt5_Array,
  11.                          MainActivity.SyllabusChildBelt6_Array,
  12.                          MainActivity.SyllabusChildBelt7_Array,
  13.                          MainActivity.SyllabusChildBelt8_Array,
  14.                          MainActivity.SyllabusChildBelt9_Array,
  15.                          MainActivity.SyllabusChildBelt10_Array,
  16.                          MainActivity.SyllabusChildBelt11_Array,
  17.                          MainActivity.SyllabusChildBelt12_Array,
  18.                          MainActivity.SyllabusChildBelt13_Array,
  19.                          MainActivity.SyllabusChildBelt14_Array
  20.                          
  21.                         };
Parsed in 0.034 seconds, using GeSHi 1.0.8.4

As you see in my code it seems very redundant and I do not know if its safe practice. but please do tell me about books???
igorski88
Junior Developer
Junior Developer
 
Posts: 17
Joined: Sun Feb 27, 2011 9:03 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 20 guests