allora...sono riuscito a mettere 2 CHOICE GROUP in un unica midlet...posto il codice:
codice:import javax.microedition.midlet.*; import javax.microedition.lcdui.*; public class quiz2 extends MIDlet implements ItemStateListener, CommandListener { private Display display; // Reference to display object private Form fmMain; // The main form private Form fmMain2; private Command cmExit; // A Command to exit the MIDlet private Command cmView; // View the choice selected private ChoiceGroup cgEmail,cgEmail2; // Choice group private int replyIndex,replyIndex2; // Index of "reply" in choice group private int choiceGroupIndex,choiceGroupIndex2; // Index of choice group on form public quiz2() { display = Display.getDisplay(this); // Create an exclusive (radio) choice group cgEmail = new ChoiceGroup("Email Options", Choice.EXCLUSIVE); cgEmail2 = new ChoiceGroup("Options", Choice.EXCLUSIVE); // Append options, with no associated images cgEmail.append("Read", null); replyIndex = cgEmail.append("Reply", null); cgEmail.append("Forward", null); cgEmail.append("Delete", null); // Set "reply" as the default/selected option cgEmail.setSelectedIndex(replyIndex, true); // Append options, with no associated images cgEmail2.append("dsasd", null); replyIndex2 = cgEmail2.append("sdly", null); cgEmail2.append("asd", null); cgEmail2.append("Forsdward", null); // Set "reply" as the default/selected option cgEmail2.setSelectedIndex(replyIndex2, true); cmExit = new Command("Exit", Command.EXIT, 1); cmView = new Command("View", Command.SCREEN,2); // Create Form, add components, listen for events fmMain = new Form(""); choiceGroupIndex = fmMain.append(cgEmail); choiceGroupIndex2 = fmMain.append(cgEmail2); fmMain.addCommand(cmExit); fmMain.addCommand(cmView); fmMain.setCommandListener(this); } // Called by application manager to start the MIDlet. public void startApp() { display.setCurrent(fmMain); } public void pauseApp() { } public void destroyApp(boolean unconditional) { } public void commandAction(Command c, Displayable s) { if (c == cmView) { // Build a string showing which option was selected /*StringItem stiMessage = new StringItem("You selected: ", cgEmail.getString(cgEmail.getSelectedIndex())); StringItem stiMessage2 = new StringItem("You selected: ", cgEmail2.getString(cgEmail2.getSelectedIndex())); fmMain.append(stiMessage); fmMain.append(stiMessage2);*/ StringItem stiMessage = new StringItem("You selected: ", cgEmail.getString(cgEmail.getSelectedIndex())); fmMain.append(stiMessage); // Delete the choice group & view button fmMain.delete(choiceGroupIndex); fmMain.delete(choiceGroupIndex2); fmMain.removeCommand(cmView); } else if (c == cmExit) { destroyApp(false); notifyDestroyed(); } } public void itemStateChanged(Item item) { } }
ora pero la StringItem stiMessage nn mi restituisce nessun risultato...cm se l'indice non fosse memorizzato...mentre se lo faccio per la seconda CHOICEGROUP mi da il risultato..cosč che nn va?

Rispondi quotando