Problemas no Aplicativo - ChoiceGroup

1 resposta
J

fala pessoal....

Alguem sabe o que acontece com essa Midlet... O aplicativo tem que atualizar a lista de acordo com o que se escolhe no ChoiceGroup.POPUP:

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

public class Midlet1 extends MIDlet implements CommandListener{
    Display display;
    Form frmMain;
    ChoiceGroup groupOpcoes, groupBand;
    String[] lstOpcoes = {"A", "B", "C"};
    String[] lstA = {"A1", "A2", "A3", "A4", "A5"};
    String[] lstB = {"B1", "B2", "B3", "B4", "B5"};
    String[] lstC = {"C1", "C2", "C3", "C4", "C5"};
    
    public Midlet1() {
        display = Display.getDisplay(this);
		frmMain = new Form("Bem-vindo");
		
        groupOpcoes = new ChoiceGroup ("Teste", Choice.POPUP);
        frmMain.append(groupOpcoes);
        
        for (int i = 0; i < lstOpcoes.length; i++) {
            groupOpcoes.append(i+1 + ". "+lstOpcoes[i], null);
        }
        
          switch (groupOpcoes.getSelectedIndex()){
            case 0 : {
                groupBand = new ChoiceGroup(groupOpcoes.getString(groupOpcoes.getSelectedIndex()), Choice.MULTIPLE);
                for (int i = 0; i < lstA.length; i++)
                    groupBand.append(lstA[i], null);
            }
            case 1 : {
                groupBand = new ChoiceGroup(groupOpcoes.getString(groupOpcoes.getSelectedIndex()), Choice.MULTIPLE);
                for (int i = 0; i < lstB.length; i++)
                    groupBand.append(lstB[i], null);
            }
            case 2: {
                groupBand = new ChoiceGroup(groupOpcoes.getString(groupOpcoes.getSelectedIndex()), Choice.MULTIPLE);
                for (int i = 0; i < lstC.length; i++)
                    groupBand.append(lstC[i], null);
            }
        }
        frmMain.append(groupBand);
        frmMain.setCommandListener(this);
    }
    
    public void startApp() {
        display.setCurrent(frmMain);
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }

    public void commandAction(Command c, Displayable d) {

    }
}

1 Resposta

J

Assim:

//Ouvinte
frmMain.setItemStateListener(new ItemStateListener() {
                public void itemStateChanged(Item item) {
                    if (item instanceof ChoiceGroup) {
                        ChoiceGroup obj = (ChoiceGroup)item;
                        if (obj == groupOpcoes) {
                            //bloco de comandos
                        }
                    }
                }
        
             });

Joao

Criado 2 de maio de 2008
Ultima resposta 3 de mai. de 2008
Respostas 1
Participantes 1