menus and primitive graphics

4 messages - 77 views

Hi,

 

I have two questions about Kluix:

 

1-) Can I add an item to the menu in runtime? I mean, I start a screen with 3 items in a menu, but when a user do some action the menu will recieve one more item.

 

2-) Can I use a menu and also draw primitive graphics from the J2ME API like fillRect() in the middle of the screen?

 

thanks

1) Yes. Several way can permit to do this, but you can.

- add a new MenuItem widget

- consider MenuPopup as a dynamic list builded from a DataProvider as a simple list on a screen

- relead a new XML with a complete new menu

 

2) Yes. If you want a widget with a special drawing capabilities, simply create a new custom widget.

thanks for replying.

 

See this case:

I did a xml file with:

<screenFirstMenu onAction="exit">Exit</screenFirstMenu>
<screenSecondmenu>
    more...
    <menuPopup>
        <menuItem onAction="about">
            About
        </menuItem>
        <menuItem onAction="exitConfirm">
            Exit
        </menuItem>
        <menuItem onAction="get">
            GET
        </menuItem>
    </menuPopup>
</screenSecondmenu>

 

Then, I have in my App two menus: "Exit" and "more".

When I click "more" is shows three menuitems: "About", "Exit" and "GET".

Now I want to del, in runtime, to del one of these three Items.

I tryed:

screen.getSecondMenu().getChild().remove();

but it removes the first one, how can I remove other, by saying, giving an index?

 

thnaks

 

Widget.getChild() return the first child of a widget. But widgets are linked list elements, to retrieve next children, you can iterate like :

for (Widget widget = parentWidget.getChild(); widget != null; widget = widget.net) {

...

}

 

Else, to retrieve a specific widget, simple add an ID.

...

<menuItem id="getMenuItem" onAction="get">GET</menuItem>

...

And you can retrieve it from any ancestror widget like the screen for example.

Widget widget = screen.getWidget("getMenuItem");

 

Else again, instead of remove a widget (which is definitive), you can hide it with visible = false. Visible is an attribute, then you can update the value by a dataProvider :

...

<menuItem onAction="get">

<_visible>@{getIsVisible}</visible>

GET

</menuItem>

...

And simple change the 'getIsVisible' property value from associated dataProvider. (more info on dataProvider here)

Caution, getIsVisible property value need to be a "String" representation of a boolean : "true", or "false".