×

Discussion Board

Results 1 to 8 of 8
  1. #1
    Registered User
    Join Date
    May 2007
    Posts
    8

    Exclamation Help with Choicegroups in J2ME

    Hi, I'm new here, I have this project from my school where I have to send information from cellphone to cellphone, the one who sends the information has to fill some spaces including a choicegroup, but the thing is, that if the first option is chosen, the textbox next to it, it's uneditable, but with the other options, the textbox can be written, in the code I wrote, when I compile it, it doesn't have any error, but when I run the code, instead of execute the options, the textbox is always uneditable, and I don't know what's going on, please, someone help, this is the code:

    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.MIDlet;

    public class ResulDemo
    extends MIDlet
    implements CommandListener, ItemCommandListener{
    private final static String[] TypeCas = {
    "B-Basic", "A-Aside", "E-Extraordinary", "S-Special" };
    int dx;
    private ChoiceGroup types;
    private StringItem item;
    private Display display;
    private Form mainForm;
    private final static Command CMD_GO = new Command("Go", Command.ITEM, 1);
    private final static Command CMD_PRESS = new Command("Press", Command.ITEM, 1);
    private final static Command CMD_EXIT = new Command("Exit", Command.EXIT, 1);

    protected void startApp() {
    display = Display.getDisplay(this);
    mainForm = new Form("Results");
    mainForm.append(new TextField("Sectin", "", 4, TextField.NUMERIC));
    ChoiceGroup types = new ChoiceGroup("Type:", ChoiceGroup.POPUP,TypeCas, null);
    mainForm.append(types);
    dx = types.getSelectedIndex();
    StringItem item = new StringItem("",null);
    mainForm.append(item);
    if (TypeCas[dx]==TypeCas[0]){
    mainForm.append(new TextField("Type","",2,TextField.UNEDITABLE));
    item = new StringItem("Next","",Item.BUTTON);
    item.setDefaultCommand(CMD_PRESS);
    item.setItemCommandListener(this);
    mainForm.append(item);
    }else {
    mainForm.append(new TextField("Type","",2,TextField.NUMERIC));
    item = new StringItem("Next","",Item.BUTTON);
    item.setDefaultCommand(CMD_PRESS);
    item.setItemCommandListener(this);
    mainForm.append(item);
    }
    mainForm.addCommand(CMD_EXIT);
    mainForm.setCommandListener(this);
    display.setCurrent(mainForm);
    }

    public void commandAction(Command c, Item item) {
    System.out.println("Continue....");

    }

    public void commandAction(Command c, Displayable d) {
    destroyApp(false);
    notifyDestroyed();
    }

    protected void destroyApp(boolean unconditional) {
    }
    protected void pauseApp() {
    }
    }

    Please, someone help me, I can't continue with the code if I can't make the choicegroup work...

  2. #2
    Regular Contributor
    Join Date
    Aug 2006
    Location
    Rawalpindi, Pakistan
    Posts
    486

    Re: Help with Choicegroups in J2ME

    ur using new textfiled while appending to a form. every time u use the word new system always creates a new object of the textfield so ur previous textfield is not being refered to. So i would suggest if u create one texfield like u have created choicegroup and then make this field as editable and uneditable.
    Regards
    Nouman

  3. #3
    Registered User
    Join Date
    May 2007
    Posts
    8

    Re: Help with Choicegroups in J2ME

    Thanks for the answer, I was trying to do that, but then, if I declare the textfield at the beginning, how can I make it uneditable? what method can I use? (something like type.UNEDITABLE?), and on the other hand, even that way, if I choose an option on the choicegroup with the code I have 'til now, no matter if a new textfield is being created each time, it would be able to appear uneditable on the form if I choose the first option, and editable if I choose on of the others, but even if I'm creating a new one, it remains uneditable, I think is the method I'm using, but I don't know what to use anymore, can you suggest me any other method? Thanks.

  4. #4
    Registered User
    Join Date
    Aug 2005
    Posts
    22

    Re: Help with Choicegroups in J2ME

    Hi,

    If I am reading you right, the effect that you would like to achieve is having the TextField editability depending on the selection made on a preceeding ChoiceGroup, I don't believe it can be achieved using the standard Form.

    As the SelectedIndex attribute from ChoiceGroup is not known until a key is pressed, such as <Select> or <Ok>, naturally you wouldn't be able to effect a TextField attribute change in the same Form.

    Having said that, you may split the ChoiceGroup and TextField into 2 sequential Forms, ie List followed by TextBox.

    Alternatively, you may have to handle these directly, by implementing your own Form through Canvas, and almost writing your own ChoiceGroup and TextField.

    Hope that helps,

  5. #5
    Regular Contributor
    Join Date
    Aug 2006
    Location
    Rawalpindi, Pakistan
    Posts
    486

    Re: Help with Choicegroups in J2ME

    Also a lot more easier solution can be. if the user selects the choice group u can display another form with eidtable or uneditable textfield according to choice selected. meaning if user selects uneditable choice. create a new form and add an editable text field and show the form with a back button. its the same process as epalite explained with respect to list. i am just saying it with respect to choice group.
    Regards
    Nouman

  6. #6
    Registered User
    Join Date
    May 2007
    Posts
    8

    Re: Help with Choicegroups in J2ME

    Thanks for the help, I could resolve it =D, but now I have another problem XD, in the next screen the user have to fill some fields, and in the next one, this information is printed on screen to see if it's correct by pressing YES, and if it's not by pressing NO, but if it's not it has to go back to the preview screen, I'm using buttons and all of that in the commandaction method, but when I run the program, when I press yes or no, it doesn't happen anything and it keeps giving me exceptions, here is the code of that part, I'm using methods to call some of the screens:

    public void commandAction(Command c, Item boton) {
    if (c == CMD_PRESS){
    counter();//this is the next screen from the choicegroup
    }else{
    if (c== CMD_PRESS2){ //after I fill the fields from counter
    mainForm4 = new Form("COUNTER");
    title = TypeCas[dx];
    section = seccion.getString();//I have defined these 3 terms at the beginning
    number = numCas.getString();
    tipo = section + title + number;
    mainForm4.append(tipo + "\n");
    part = suma.getString();//I'm taking what's on the fields on the preview screen
    mainForm4.append("SUM: "+ part + "\n");
    part = resta.getString();
    mainForm4.append("REST: " + part + "\n");
    part = mult.getString();
    mainForm4.append("MULTIPLICATION: "+ part +"\n");
    part = divi.getString();
    mainForm4.append("DIVISION "+ part +"\n");
    mainForm4.append("¿Is it correct?"+"\n");
    boton = new StringItem ("YES","",Item.BUTTON);
    boton.setDefaultCommand(CMD_SI);//I should go to the next screen
    boton.setItemCommandListener(this);
    mainForm4.append(boton);
    boton = new StringItem("No","",Item.BUTTON);
    boton.setDefaultCommand(CMD_NO); //I should go back to counter
    boton.setItemCommandListener(this);
    mainForm4.append(boton);
    display.setCurrent(mainForm4);
    }else{
    if (c==CMD_NO){
    counter);
    }else{
    if (c==CMD_SI){
    results();
    }
    }//else3

    }//else2
    }//if
    }
    public void counter(){//I fill the spaces on this screen
    mainForm2 = new Form("COUNTER");
    mainForm2.append(sum);
    mainForm2.append(rest);
    mainForm2.append(mult);
    mainForm2.append(divi);
    boton = new StringItem ("Next","",Item.BUTTON);
    boton.setDefaultCommand(CMD_PRESS2);
    boton.setItemCommandListener(this);
    mainForm2.append(boton);
    display.setCurrent(mainForm2);
    }
    public void results(){//this should be the next screen by clicking yes
    mainForm5 = new Form("RESULTS");
    mainForm5.append(sum);
    mainForm5.append(rest);
    mainForm5.append(mult);
    mainForm5.append(divi);
    boton = new StringItem ("Next","",Item.BUTTON);
    boton.setDefaultCommand(CMD_PRESS4);
    boton.setItemCommandListener(this);
    mainForm5.append(boton);
    display.setCurrent(mainForm5);
    }
    public void commandAction(Command c, Displayable d) {
    if (c == cmd){
    dx=types.getSelectedIndex();
    if (types.isSelected(0)){ //This is from the choicegroup before
    mainForm3=new Form("");
    boton.setDefaultCommand(CMD_PRESS);
    boton.setItemCommandListener(this);
    mainForm3.append(boton);
    display.setCurrent(mainForm3);
    }else{
    mainForm3=new Form("");
    mainForm3.append(numCas);
    boton.setDefaultCommand(CMD_PRESS);
    boton.setItemCommandListener(this);
    mainForm3.append(boton);
    display.setCurrent(mainForm3);
    }
    }else { if (cmd==CMD_EXIT){
    destroyApp(false);
    notifyDestroyed();}
    }
    }

    I have read that there's a Back command but I don't know how to use it or implement it on the code, I would thank any kind of help.

  7. #7
    Regular Contributor
    Join Date
    Aug 2006
    Location
    Rawalpindi, Pakistan
    Posts
    486

    Re: Help with Choicegroups in J2ME

    if u want to use a back command simply do this when creating a Command.

    Command back= new Command("Back",Command.back,2);
    and in commandAction function define this check

    public void commandAction(Command c, Displayable s)
    {

    if( c.getCommandType()==Command.back)
    {
    //define ur action here.
    }

    }
    Regards
    Nouman

  8. #8
    Registered User
    Join Date
    May 2007
    Posts
    8

    Re: Help with Choicegroups in J2ME

    But if I want to use a button? Does it work with a command not defined as an item?

Similar Threads

  1. How can the WAP browser communicate to J2ME application?
    By hbfornies in forum Mobile Java General
    Replies: 20
    Last Post: 2007-03-02, 16:32
  2. J2ME Polish Version 1.0 RC6
    By enough in forum Mobile Java General
    Replies: 1
    Last Post: 2004-07-20, 11:25
  3. J2ME Polish 1.0 RC1!
    By enough in forum Mobile Java General
    Replies: 1
    Last Post: 2004-06-15, 02:53
  4. TinyLine SVG Minute Toolkit: Optimizing SVG for J2ME
    By girow in forum Mobile Java Media (Graphics & Sounds)
    Replies: 0
    Last Post: 2003-05-05, 18:44
  5. TinyLine SVG Minute Toolkit for J2ME: version 1.4 released
    By girow in forum Mobile Java General
    Replies: 0
    Last Post: 2003-05-05, 16:25

Posting Permissions

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