Android lwuit softkeys when bringing up a dialog
when you pop up a dialog on android the options dont appear until the user hits the menu key, is there a way to have them pop up automatically without needing to his the menu key??
thank you that worked - although now my empty string where there should be no option shows an empty button, and my button with OK on its sort of off center, I will try " OK " to fix it and another overriden .show()
Now im trying to use:
public static
Command show
(java.lang.String title,
<a style="margin: 0px; padding: 0px; color: rgb(0, 102, 153); text-decoration: none;" title="class in com.sun.lwuit" href="http://lwuit.java.net/javadocs/com/sun/lwuit/Component.html">Component</a> body,
<a style="margin: 0px; padding: 0px; color: rgb(0, 102, 153); text-decoration: none;" title="class in com.sun.lwuit" href="http://lwuit.java.net/javadocs/com/sun/lwuit/Command.html">Command</a>[] cmds) <a style="margin: 0px; padding: 0px; color: rgb(0, 102, 153); text-decoration: none;" title="class in com.sun.lwuit" href="http://lwuit.java.net/javadocs/com/sun/lwuit/Command.html">Command</a>[] cmds)
But what is component supposed to be???? Very confused - all this to avoid an empty button..
Fixed it like this:
//brings up a dialog showing error message
public static void showInfo(String info)
{
//#ifdef ANDROIDBUILD
Dialog.setCommandsAsButtons(true);
//lots of nonsense to get android dialogs to look right
if (androidOK==null)
{
androidOK = new com.sun.lwuit.Command(" OK ");
androidLabels = new com.sun.lwuit.Command[] {androidOK};
androidTextArea.setEditable(false);
}
androidTextArea.setText(info);
Dialog.show("Info", (Component)androidTextArea, androidLabels);//" OK ", "" );//fixes fucked up buttons in android
//#else
Dialog.show("Info", info, "OK", "");
//#endif
}
static com.sun.lwuit.Command androidOK;
static com.sun.lwuit.Command[] androidLabels;
static com.sun.lwuit.TextArea androidTextArea = new com.sun.lwuit.TextArea();
One other question, when buttons are focused the text is all the way to the left - its fine when theyre not focused, any ideas how i solve?
also my solution above fails when i try to show dialog again - I get:
component is already contained in container
Any ideas why this is so? and how i can stop it?
OK this works:
Dialog.setCommandsAsButtons(true);
//lots of nonsense to get android dialogs to look right
Dialog d = new Dialog();
//if (androidOK==null)
{
androidOK = new com.sun.lwuit.Command(" OK ");
androidLabels = new com.sun.lwuit.Command[] {androidOK};
androidTextArea.setEditable(false);
androidTextArea.setText(info);
d.removeComponent((Component)androidTextArea);
d.show("Info", (Component)androidTextArea, androidLabels);//" OK ", "" );//fixes fucked up buttons in android
}
One last point, If I want one button as above its fine, if I want 2 buttons like below:
//#ifdef ANDROIDBUILD
Dialog.setCommandsAsButtons(true);
//lots of nonsense to get android dialogs to look right
Dialog d = new Dialog();
//if (androidOK==null)
{
androidOK = new com.sun.lwuit.Command("OK");
com.sun.lwuit.Command androidOK2 = new com.sun.lwuit.Command("Cancel");
androidLabels = new com.sun.lwuit.Command[] {androidOK, androidOK2};
androidTextArea.setEditable(false);
androidTextArea.setText(info);
d.removeComponent((Component)androidTextArea);
com.sun.lwuit.Command c = d.show("Info", (Component)androidTextArea, androidLabels);//" OK ", "" );//fixes fucked up buttons in android
if (c.getCommandName().equals("OK"))
{
return true;
}
else
{
return false;
}
}
//#else
The OK button is on the dialog fine but the Cancel one is half off the dialog and looks messy - how do I get them both to fit nicely into the dialog??
You should pass null for an emty command in a dialog not an empty string.
The component in the dialog can be anything. We just create a TextArea make it uneditable and set its UIID to DialogBody.
You can use an image/animation or whatever as the body of the dialog.
Hi - whats the equivlant of :
Dialog.setCommandsAsButtons(true);
For a form? I want the softkey options to appear at the bottom without user having to press the menu key?
thanks.





With our native Android look and feel they appear as buttons in the dialog (its part of Codename One). You can enable something like this using the flag Dialog.setCommandsAsButtons()