Context Sensitive Menus – Java ME

Context Sensitive Menus – Java ME

谢绝鈎搭 发布于 2021-11-28 字数 758 浏览 908 回复 1 原文

I'm trying to build a context sensitive based command list. I set the command.ITEM option for all my command buttons. But I couldn't find a way how to provide the following functionality:

I have a list of values say A, B,C
For A, my command menu should contain 2,4
When I move the selection (cursor) to B, my commands menu should have 1,3
When I move to C, commands should have 2,1
Again when I move back to A, it should have A's command menu (2,4)

It can be used for a list of files and directories:

When a file is selected, I want to show options (commands) open, edit and delete. When I select a directory, I want to show commands just open and delete.

Thanks in advance for any help pointing to the right direction.

如果你对这篇文章有疑问,欢迎到本站 社区 发帖提问或使用手Q扫描下方二维码加群参与讨论,获取更多帮助。

扫码加入群聊

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

魔法唧唧 2022-06-07 1 楼

The specification for the javax.microedition.lcdui.Form class (Which I assume is what you're using) states:

"These traversing and scrolling operations do not cause application-visible events"

There is also no method called before the command menu gets displayed.

All this means that you can't do what you want here using a Form.

Depending on the J2ME implementation on the specific phone you're targetting, javax.microedition.lcdui.CustomItem.getInteractionModes() might tell you whether you can use a single CustomItem in your form to create a context-sensitive menu.

The only sure way to do this on all phones is to use a javax.microedition.lcdui.Canvas and re-implement the controls you need by drawing them yourself. You can then keep track of which one is "selected" and populate your own command menu before displaying it in response to low-level keyPressed() events.

You might want to look into the LWUIT open source library for an intermediary solution.