×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Jul 2012
    Posts
    4

    Question J2ME choicegroups help

    Hello all,

    I have two choicegroups on the form.I'm using POPUP style.
    Both choicegroups are populated with items called hours,minutes,seconds using append().How to make,when user selects,for example,hours in first choicegroup,to have only minutes and seconds in the second choicegroup.Or when user select minutes,to have hours and seconds in the second choicegroup etc...

    Thanks in advance...

  2. #2
    Nokia Developer Expert
    Join Date
    May 2012
    Location
    Espoo
    Posts
    224

    Re: J2ME choicegroups help

    Hi abstraction and welcome to Nokia developer discussion boards,

    How to make,when user selects,for example,hours in first choicegroup,to have only minutes and seconds in the second choicegroup.Or when user select minutes,to have hours and seconds in the second choicegroup etc...
    Selecting item in first ChoiceGroup can display desired items in second ChoiceGroup by
    implementing ItemStateListener and listening to first ChoiceGroup itemStateChanged event like below:

    public class ChoiceGroupTest extends MIDlet implements ItemStateListener, CommandListener {

    private ChoiceGroup firstCG;
    private ChoiceGroup secondCG;
    private int defaultIndex;


    protected void startApp() throws MIDletStateChangeException {
    Form form=new Form("form");
    Display.getDisplay( this ).setCurrent(form);

    firstCG = new ChoiceGroup("Select Time Format", Choice.POPUP);
    secondCG = new ChoiceGroup("Select Time", Choice.POPUP);
    defaultIndex = firstCG.append("Hours", null);
    firstCG.append("Minute", null);
    firstCG.append("Seconds", null);
    firstCG.setSelectedIndex(defaultIndex, true);
    setTime();
    form.append(firstCG);
    form.append(secondCG);
    }


    public void itemStateChanged(Item item) {
    if (item == firstCG) {
    defaultIndex = firstCG.getSelectedIndex();
    setTime();
    }
    }

    void setTime(){
    if(firstCG.getString(defaultIndex).equals("Hours")){
    //your logic for items to display in second ChoiceGroup
    }
    else if(firstCG.getString(defaultIndex).equals("Minutes")){
    //your logic for items to display in second ChoiceGroup
    } else if(firstCG.getString(defaultIndex).equals("Seconds")){
    //your logic for items to display in second ChoiceGroup
    }
    }
    }

  3. #3
    Registered User
    Join Date
    Jul 2012
    Posts
    4

    Re: J2ME choicegroups help

    Thank you for your help

Similar Threads

  1. ChoiceGroups changing ChoiceGroups
    By rdiuk0204 in forum Mobile Java General
    Replies: 2
    Last Post: 2010-12-01, 08:18
  2. Help with Choicegroups in J2ME
    By marianne_aw in forum Mobile Java General
    Replies: 7
    Last Post: 2007-05-28, 14:59
  3. Image size in Lists and Choicegroups !!!
    By divyas in forum Mobile Java General
    Replies: 2
    Last Post: 2006-10-11, 14:48
  4. ChoiceGroups
    By yafy in forum Mobile Java Tools & SDKs
    Replies: 2
    Last Post: 2006-02-27, 05:35
  5. ChoiceGroups & text wrapping
    By dlozdan in forum Mobile Java General
    Replies: 0
    Last Post: 2005-06-14, 12:51

Posting Permissions

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