0

I'm learning to develop some basic applications for Nokia S40 devices. I've created a couple of Commands for the user to use. The problem is that command 'no' works however 'yes' does nothing. Why is this? The example is as follows:

    final Form form = new Form("Form");
    form.append("Update?");

    final Command yes = new Command("Yes", Command.OK, 1);
    final Command no = new Command("No", Command.CANCEL, 1);

    form.addCommand(yes);
    form.addCommand(no);
    form.setCommandListener(new CommandListener() {

        public void commandAction(Command arg0, Displayable arg1) {
            // TODO Auto-generated method stub

            if (arg0 == yes) {
                System.out.println("Yes pressed");
            } else if (arg0 == no) {
                System.out.println("No Pressed");
            }
        }
    });

Any pointers or advice would be appreciated.

Cœur
  • 37,241
  • 25
  • 195
  • 267
dan983
  • 454
  • 2
  • 5
  • 19

1 Answers1

0

You cannot compare two objects using the equal sign.

You have to use the Object.equals(anotherObject) method.

So replace if (arg0 == yes) with if (arg0.equals(yes))

and if (arg0 == no) with if (arg0.equals(no)).

mr_lou
  • 1,910
  • 2
  • 14
  • 26