Events in commandAction(command, item) in MIDlet
Hi,
I'm having an issue with a Java MIDlet which I am editing in Netbeans 6.9.1.
The commandAction(command,item) is a Netbeans auto-generated method.
With the code below, if the strDeleteData text is clicked during runtime then it displays an alert with two options - Yes and No. This works fine, but I'm stuck on the next part.
The event triggered when either the Yes and No buttons are clicked is getting lost at the top of the commandAction(..,..) method. When either the Yes and No button is clicked, the event is triggered, but when it hits the commandAction method, it doesn't match strDeleteData or any of the other action commands, so the code for this will not be executed.
I'm stuck on this issue, and as Netbeans is being a pain with guarded line blocks it's making it rather tough.
So if you could please take a look and let me know if you have any ideas how I can proceed with this, that would be just super!
Code:
public void commandAction(Command command, Item item) {
// write pre-action user code here
if (item == strDeleteData) {
if (command == itemCommand) {
// write pre-action user code here
Alert deleteAlert1 = new Alert("Warning", "Are you sure you want to delete all saved data?", null, AlertType.WARNING);
Command deleteAllYes = new Command("Yes", Command.OK, 1);
Command deleteAllNo = new Command("No", Command.CANCEL, 1);
deleteAlert1.setTimeout(Alert.FOREVER);
deleteAlert1.addCommand(deleteAllYes);
deleteAlert1.addCommand(deleteAllNo);
deleteAlert1.setCommandListener(this);
getDisplay().setCurrent(deleteAlert1);
if(command == deleteAllYes){
//code goes here for when Yes is pressed
//......
}
else if(command == deleteAllNo){
//code goes here for when No is pressed
//...
}
// write post-action user code here
}
} else if (item == strSaveNewSubject) {
//code below for another Command event
}
}//end commandAction method