×

Discussion Board

Results 1 to 8 of 8
  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    9

    Choicegroup.multiple

    Hi, i was wondering how do you differentiate the value of the selected choice in a Choicegroup.multiple.

    typeChoice = new ChoiceGroup("Format:", Choice.MULTIPLE);
    typeChoice.append("Bold", null);
    typeChoice.append("Italic", null);
    form.append(typeChoice);

    System.out.println("THis is the typeCHoice value : " + typeChoice.getSelectedIndex());

    and when i s.o.p for the value, it always return a -1, with that i can't set an if/else for the value.

  2. #2
    Super Contributor
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: Choicegroup.multiple

    From the Java ME Developers Library:
    int getSelectedFlags(boolean[] selectedArray_return)

    Queries the state of a ChoiceGroup and returns the state of all elements in the boolean array selectedArray_return.
    Basically you have to have a boolean array that will be used to return the state of the items in the ChoiceGroup (true for selected, false otherwise).

    Here is an example of how to use a multiple ChoiceGroup:
    http://www.java2s.com/Code/Java/J2ME...hoiceGroup.htm

  3. #3
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: Choicegroup.multiple

    Quote Originally Posted by nabenabu View Post
    Hi, i was wondering how do you differentiate the value of the selected choice in a Choicegroup.multiple.

    typeChoice = new ChoiceGroup("Format:", Choice.MULTIPLE);
    typeChoice.append("Bold", null);
    typeChoice.append("Italic", null);
    form.append(typeChoice);

    System.out.println("THis is the typeCHoice value : " + typeChoice.getSelectedIndex());

    and when i s.o.p for the value, it always return a -1, with that i can't set an if/else for the value.
    Hi please read this carefully,


    Returns the index number of an element in the ChoiceGroup that is selected. For ChoiceGroup objects of type EXCLUSIVE and POPUP there is at most one element selected, so this method is useful for determining the user's choice. Returns -1 if there are no elements in the ChoiceGroup.

    For ChoiceGroup objects of type MULTIPLE, this always returns -1 because no single value can in general represent the state of such a ChoiceGroup
    you will be having the get selected index at the selected value -
    Thanks,
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  4. #4
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: Choicegroup.multiple

    Hi,
    Find the code..tested one.
    Please set the choice group type.as per the need,
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;

    public class ChoiceGroupDemo extends MIDlet implements CommandListener
    {
    private boolean boolMotion=false;
    Display mDisplay;
    ChoiceGroup cg;
    Command cmd;
    Form frm=new Form("Choice Group Demo");
    public void commandAction(Command c, Displayable d)
    {
    System.out.println("index - "+cg.getSelectedIndex());
    }

    public void startApp()
    {
    cg=new ChoiceGroup("Choose Movie:",Choice.EXCLUSIVE);
    cmd=new Command("OK",Command.OK,1);

    cg.append("Horror",null);
    cg.append("Comedy",null);
    cg.append("Action",null);
    frm.append(cg);
    frm.addCommand(cmd);
    frm.setCommandListener(this);

    mDisplay = Display.getDisplay(this);
    mDisplay.setCurrent(frm);
    }
    public void pauseApp()
    {}
    public void destroyApp(boolean unconditional)
    {}
    }
    Thanks,
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  5. #5
    Super Contributor
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: Choicegroup.multiple

    Raj, don't you think it would be better to wait and see if the example that has already been provided helps instead of giving another one (which isn't MULTIPLE, but EXCLUSIVE and doesn't really explain the solution)?

  6. #6
    Registered User
    Join Date
    Nov 2008
    Posts
    9

    Re: Choicegroup.multiple

    Quote Originally Posted by bogdan.galiceanu View Post
    From the
    Here is an example of how to use a multiple ChoiceGroup:
    http://www.java2s.com/Code/Java/J2ME...hoiceGroup.htm
    the above example worked nicely, thanks a lot.

    another question:
    is is possible to incooperate different style in a font itself? eg. having STYLE_ITALICS, STYLE_BOLD, STYLE_UNDERLINED all in the same font

  7. #7
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: Choicegroup.multiple

    Quote Originally Posted by nabenabu View Post
    is is possible to incooperate different style in a font itself? eg. having STYLE_ITALICS, STYLE_BOLD, STYLE_UNDERLINED all in the same font
    Hi,
    Well think how it can be done..if you have created the 1 font say FONT1 as global then how you can do it..no..you can not..

    However the best workaround would be like just
    @ Either create the different fonts or
    @ Just set the font directly like -
    g.setFont(Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD,Font.SIZE_MEDIUM));
    for the different fonts do provide the different STYLES .
    Hope these lines can help,
    Thanks,
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  8. #8
    Super Contributor
    Join Date
    Apr 2007
    Posts
    2,708

    Re: Choicegroup.multiple

    btw,
    coming back to the coichegroup question :
    u can even check out the text of the selected choicegroup, so there are several methods...
    u can check the boolean array as mentioned,
    u can check the index (u might want to save the index every item has received when u added the to the choicegroup)
    or as I mentioned u can check the text of the selected index (and for example compare it with ur own labels)...

Posting Permissions

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