How to access the multiple choiceGroup in midlet class as selection

91 Views Asked by At

I have created one class which extends MIDLet. I have created another class more than one choiceGroup, textField, and many more. I want to use at a time only choiceGroup or textField .. Please help me. When I select on item1 only choiceGroup1 and textField will show on screen.

package tesdt;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class testMidlet extends MIDlet implements CommandListener 
{
    Display display;
    Form form;
    Command cmdNext;
    ChoiceGroup gr4;
    public testMidlet()
    {
        display=Display.getDisplay(this);
        form =new Form("Hello World");
        cmdNext=new Command("Next", Command.SCREEN,1);
        form.addCommand(cmdNext);
        form.setCommandListener(this);
        gr4=new ChoiceGroup("Select",ChoiceGroup.EXCLUSIVE);
        gr4.append("item1", null);
        gr4.append("item2", null);
        gr4.append("item3", null);
        form.append(gr4);
    }
    public void startApp() 
    {
        display.setCurrent(form);
    }
    public void pauseApp() {
    }
    public void destroyApp(boolean unconditional) 
    {
    }
    public void commandAction(Command c, Displayable d) throws UnsupportedOperationException
    {
        if(c==cmdNext || gr4.getSelectedIndex()==1)
        {
            GUITest guitest=new GUITest();
            display.setCurrent(guitest);
        }
    }
}

package tesdt;
import javax.microedition.lcdui.*;
public class GUITest extends Form
{
    TextField tf1,tf2,tf3;
    ChoiceGroup gr1,gr2,gr3;
    String[] gr1Item={"item1","item2","item3","item4"};
    String[] gr2Item={"Name","Age","Sex","DOB"};
    String[] gr3Item={"Delhi","Mumbai","Patna","Bangalore"};
    Command com; 
//    testMidlet testMidlet; 
    public GUITest()
    {
        super("hi");
        com=new Command("Next on", Command.SCREEN,1);
    }
    public Command getCom()
    {
       return com;
    }
    public ChoiceGroup getGr1()
    {
       return gr1;
    }
    public void setGr1()
    {
        gr1=new ChoiceGroup("Item",ChoiceGroup.EXCLUSIVE,gr1Item,null);
        append(gr1);
    }
    public ChoiceGroup getGr2()
    {
        return gr2;
    }
    public void setGr2()
    {
        gr2=new ChoiceGroup("Record",List.EXCLUSIVE,gr2Item,null);
        append(gr2);
    }
    public ChoiceGroup getGr3()
    {
        return gr3;
    }
    public void setGr3()
    {
        gr3=new ChoiceGroup("Item",ChoiceGroup.EXCLUSIVE,gr3Item,null);
        append(gr3);
    }
    public TextField getTf1()
    {
        return tf1;
    }
    public void setTf1()
    {
        tf1=new TextField("Record","Enter Item",20,TextField.ANY);
        append(tf1);
    }
    public TextField getTf2()
    {
        return tf2;
    }
    public void setTf2()
    {
        tf2=new TextField("Item","Enter Record",20,TextField.ANY);
        append(tf2);
    }
    public TextField getTf3()
    {
        return tf3;
    }
    public void setTf3()
    {
        tf3=new TextField("Item","Enter City",20,TextField.ANY);     
        append(tf3);

    }
}

}
0

There are 0 best solutions below