Skip to main content

can we create an alert box with two buttons?

3 replies [Last post]
sonalagar
Offline
Joined: 2009-03-06

can we create an alert box with two buttons saying YES...NO
How to show tehse buttons,can we add two images for this?if yes how to add two images to alert box???

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jaywayjohan
Offline
Joined: 2008-06-18

Hi,

you could try the Alert class in MIDP. You could add one Command of type Command.OK and one Command of type Command.CANCEL, with the appropriate labels.

The Alert class has the opportunity to show one Image. If you want to show several images, you have to merge the yourself. However, as far as I know it is not possible to add images to the Command objects.

Regards
Johan

sonalagar
Offline
Joined: 2009-03-06

actually what I need is to show two buttons on aletr box saying yes & no,user should be able to select those buttons.
Adding commands wud simply able to handle the action of soft keys,but how to add * or display these buttons on alert box

Here is my code
Here is my code.....
{form = new Form("Alert check");
next = new Command("NEXT", Command.OK, 1);
exit = new Command("EXIT", Command.EXIT, 1);
form.addCommand(next);
form.addCommand(exit);
form.setCommandListener(this);
display = Display.getDisplay(this);
display.setCurrent(form);
alert = new Alert("Alert YES/NO", "Press YES or NO",null, AlertType.INFO);
yes = new Command("Yes", Command.EXIT, 0);
no = new Command("No", Command.EXIT, 1);
alert.setTimeout(Alert.FOREVER);
alert.addCommand(yes);
alert.addCommand(no);
alert.setCommandListener(this);

}

public void commandAction(Command command, Displayable displayable)
{

if (command == yes)
{
str="Pressed: YES";
form.append(str);
display.setCurrent(form);
}

else if (command == no)
{
str="Pressed: NO";
form.append(str);
display.setCurrent(form);

}

else if (command == next)
{
String s1 = any.getString();
if (s1.equals("") || Integer.parseInt(s1) == 5) {
alert.setString(" ARE YOU SURE!!!!");
alert.setTimeout(Alert.FOREVER);
Display.getDisplay(this).setCurrent(alert);
}
}

else if (command == exit)
destroyApp(true);
}

jaywayjohan
Offline
Joined: 2008-06-18

Hi,

you could try the Alert class in MIDP. You could add one Command of type Command.OK and one Command of type Command.CANCEL, with the appropriate labels.

The Alert class has the opportunity to show one Image. If you want to show several images, you have to merge the yourself. However, as far as I know it is not possible to add images to the Command objects.

Regards
Johan