Skip to main content

Android lwuit softkeys when bringing up a dialog

8 replies [Last post]
68060
Offline
Joined: 2011-08-29
Points: 0

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??

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
vprise
Offline
Joined: 2003-11-07
Points: 0

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()

68060
Offline
Joined: 2011-08-29
Points: 0

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()

68060
Offline
Joined: 2011-08-29
Points: 0

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..
68060
Offline
Joined: 2011-08-29
Points: 0

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?

68060
Offline
Joined: 2011-08-29
Points: 0

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?

68060
Offline
Joined: 2011-08-29
Points: 0

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??

vprise
Offline
Joined: 2003-11-07
Points: 0

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.

68060
Offline
Joined: 2011-08-29
Points: 0

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.