robertog 9 de jul. de 2011
Achei a solução pro problema...
Se mais alguem tiver essa dúvida , ta ai como fazer
import javax.microedition.midlet.* ;
import javax.microedition.lcdui.* ;
public class Midlet1 extends MIDlet implements CommandListener {
private Form form ;
private Alert alert ;
private Command exitCommand ;
public void startApp () {
form = new Form ( "ConfirmationMIDlet" );
exitCommand = new Command ( "Exit" , Command . EXIT , 1 );
form . addCommand ( exitCommand );
form . setCommandListener ( this );
Display . getDisplay ( this ). setCurrent ( form );
}
public void pauseApp () {
}
public void destroyApp ( boolean unconditional ) {
}
public void commandAction ( Command c , Displayable d ) {
if ( c == exitCommand ) {
showConfirmation ( "Confirmação" , "Você realmente deseja sair?" );
}
}
private void closeAlert () {
Display . getDisplay ( this ). setCurrent ( form );
alert = null ;
}
protected void showConfirmation ( String title , String text ) {
alert = new Alert ( title , text , null , AlertType . CONFIRMATION );
alert . addCommand ( new Command ( "Sim" , Command . OK , 1 ));
alert . addCommand ( new Command ( "Não" , Command . CANCEL , 1 ));
alert . setCommandListener ( new CommandListener () {
public void commandAction ( Command c , Displayable d ) {
if ( c . getLabel (). equals ( "Sim" )) {
notifyDestroyed ();
}
if ( c . getLabel (). equals ( "Não" )) {
closeAlert ();
}
}
});
Display . getDisplay ( this ). setCurrent ( alert , form );
}
}
godinez 11 de jul. de 2011
Perfeito, é utilizando um Alert mesmo.
Só uma sugestão, compare o command pela sua instancia, e não pela label.