×

Discussion Board

Results 1 to 9 of 9
  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    41

    How to combine elements from different List

    Hello, i am trying to figure out a way around this. i have two Implicit List in which clicking on any element in the first list will always send the user to the next list. my problem now is how does the second list remember the element that invoked it in the first list so that it can act accordingly. heres is an example:

    first List CommandAction method:


    Code:
      if (c == List.SELECT_COMMAND ){
                   /* action for selected item in the list*/
                    selection = this.getSelectedIndex();
                    switch(selection){
                        case 0:
                             wshop.displayShop();
                             break;
                        case 1:
                             wshop.displayShop();
                             break;
                    }
        
                   
                }
    2nd List commandAction method


    Code:
      public void commandAction(Command c, Displayable d) {
        
          /* action for selected item in the 2nd list that depends on element in first list*/
        
                if (c == List.SELECT_COMMAND ){
                    
                    select = slist.getSelectedIndex();
                    switch(select){
                        case 0:
                             wshop.displayForm();
                             break;
                        case 1:
                             wshop.displayForm();
                             break;
    }

    my question is if i click on case 0 in the first list and then case 1 in the second, how can i compare/combine the two so that it can perform a specific action as different actions will be invoked depending on the selection on the first list? i hope i have made my self clear on this. Thank you

  2. #2
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,073

    Re: How to combine elements from different List

    Make a gloabal variable public static--> String firstSelected; secondSelected
    Just after this like--> selection = this.getSelectedIndex();
    add firstSelected=this.getString(selection);

    and also add after select = slist.getSelectedIndex(); in 2nd list:
    secondSelected=this.getString(select);


    Now you have both selections in your public static variables and use then as you need.

    thanks,
    ~Amitabh

  3. #3
    Registered User
    Join Date
    Feb 2009
    Posts
    41

    Re: How to combine elements from different List

    thanks a lot. will give that a try.

  4. #4
    Registered User
    Join Date
    Feb 2009
    Posts
    41

    Re: How to combine elements from different List

    sorry, i have not had time to post this... this sort of works for me following your suggestion. but i want to know if it is a good style to adopt because if i have a lot of elements in the first and second list. then there will be quite a lot of comparing going on. any better suggestion to this method. thank you

    here the code:
    Code:
    /* this is the second List that compares with the first selection*/
    
    WShop.FirstSelected;  // global static variable that hold the selection from the first element.
    WShop.secondSelected; // global static variable that hold the selection from the second element.
    
     public void commandAction(Command c, Displayable d) {
            if (c == Back){
                WShop.DisplayForm();
            }
            if (c == List.SELECT_COMMAND){
              selection = this.getSelectedIndex();
              WShop.secondSelected = this.getString(selection); 
              switch(selection){
                  case 0:
                      if(WShop.FirstSelected.equals("mapStore")){ /* this code works correctly from the first selection 
                          DisplayMapStore1();                              /*in the first List. */
                      }else if(WShop.FirstSelected.equals("radStore")){
                         DisplayRadStore1();
                      }
                      // other elements to compare from the first selected
                 break;
                 
                 case 1:
                       //same as above in case 1 but will do something different
                 break;
              }
            }
        }

  5. #5
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,073

    Re: How to combine elements from different List

    Due to large no of elements in the list, if you want to get rid of the comparission in Switch Case, Create a multidimensions Array like forms(size of first, size of 2nd list), then fetch the required action from this 2 dim array.

    Then use Class.forName(forms(1st select, 2nd select)) to fetch the required form and set is to current display.

    thanks,
    ~Amitabh

  6. #6
    Registered User
    Join Date
    Feb 2009
    Posts
    41

    Re: How to combine elements from different List

    Thanks for your response. i don't really understand what you meant by using multi-dimensional. Any links or example of this will be highly welcome. I am quite happy to write it all in a switch case statement. i was just concerned with whether there will be a performance hit on memory resources and the rest if i had done so.

    but as i say, i would appreciate an example or a link to what you meant by using multi-dimensional array on forms. At least it will give me the knowledge of having another option.

    thanks again for the response.

  7. #7
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,073

    Re: How to combine elements from different List

    By multi-dimensional array I just wanted you to make 2D array, like tragetformName[10,10] it will have 10 rows and 10 columns, and say if the person has selected 3 in first list and 4 in second list -- you should just fetch the target form name from this array which will be located at point tragetformName[3,4]

    Array will look like this --> row 0 [DisplayMapStore1,DisplayRadStore1,......] // second list is rows and 1st list is column

    Then use Class.forName(forms(1st select, 2nd select)) to fetch the required form and set is to current display.

    thanks,
    ~Amitabh
    PS: I don't have any example code for this.... you would need to type it.

  8. #8
    Registered User
    Join Date
    Feb 2009
    Posts
    41

    Re: How to combine elements from different List

    so, if i understand you correctly, i create a method that takes a 2D array and pass the static variables that hold the list elements into the array.I then manually set each method associated with the array so that i can compare.

    does that mean i won't need the switch\case statement anymore?..

    sorry for bother, but for some reason am getting confused.

    thanks

  9. #9
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,073

    Re: How to combine elements from different List

    No, you need to fill in the target form name in the 2D array, which need to be called for e.g.

    In tte first list - element 1 is mapStore it is selected and in the second list 1st item is selected i.e your case 0 in the codelet you paseted.

    Then in
    if (c == List.SELECT_COMMAND){
    selection = this.getSelectedIndex();
    WShop.secondSelected = this.getString(selection);
    display.setCurrent(Class.forName(forms[1, 1]))
    }

    Where forms[1,1] is the 2D array holding the displayable form name = MapStore1 form (or the target displayable object)

    thanks,
    ~Amitabh

Similar Threads

  1. Problem with Skin enabling - disabling and Setting List in S60
    By sauvikds in forum Series 40 & S60 Platform Feedback Archive
    Replies: 6
    Last Post: 2008-08-23, 14:29
  2. File Browsing Problem
    By Marwa in forum Mobile Java Networking & Messaging & Security
    Replies: 13
    Last Post: 2007-10-10, 15:52
  3. cutom list box to popup list??
    By harish13_ks in forum Symbian
    Replies: 5
    Last Post: 2007-10-06, 12:06
  4. File browser Problem
    By Marwa in forum Mobile Java Networking & Messaging & Security
    Replies: 2
    Last Post: 2007-05-05, 22:41

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •