检查j2me中的CustomItem是否支持遍历

发布于 2024-10-05 23:41:38 字数 71 浏览 3 评论 0原文

检查j2me中的CustomItem是否支持遍历?

我应该如何检查j2me中的CustomItem是否支持遍历?

Checking the CustomItem in j2me support traversal or not?

How should I check the CustomItem in j2me support traversal or not?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

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

评论(3

风透绣罗衣 2024-10-12 23:41:38

Shiva,我认为你对穿越的理解存在一些差距。让我解释一下。

您可以向表单添加任意数量的项目。 该框架管理 MIDP 中内置的所有项目的以下

  1. 定位和所有项目的渲染
  2. 当有更多数量的项目可以容纳在屏幕中时,
  3. 滚动。处理屏幕命令和项目命令。

但是,当您扩展 CustomItem 并实现您自己的项目时,完全控制权就在实现中。考虑这样一种情况:表单包含 TextField 和 CustomItemImpl,并且您希望在 TextField 和 CustomItemImpl 之间切换。由于按键处理、命令处理和渲染全部由 CustomItemImpl 控制,因此框架必须通过某种方式知道您何时希望 TextField 拥有控制权以及何时需要将控制权传递给 CustomItemImpl。

这里是 CustomItem 中的 traverse() 方法介入的地方。当您完成 CustomItemImpl 中的渲染和捕获数据时,您返回 false;当您想要保留 CustomItemImpl 中的控件时,您返回 true。

让我进一步阐述。假设您正在实现一个 TreeItem。当焦点位于 TreeItem 上时,您需要执行以下操作:

  1. 选择节点
  2. 展开或折叠节点
  3. 导航节点

所有上述功能构成 TreeItem 实现的一部分。但是,当您将 KEY_UP 移动到树的第一个节点或 KEY_DOWN 移动到树的最后一个节点时,您希望移动到 TextField / 与此 TreeItem 相邻的任何其他项目。让框架知道您的意图的方式是,

  1. 当选择 KEY_UP 且焦点位于树的第一个节点时,
  2. 在 traverse() 方法中返回 false 当选择 KEY_DOWN 且焦点位于最后一个节点时,在 traverse() 方法中返回 false树的。

希望这能澄清您的疑问。我强烈建议您查看这个特定的示例更具体的说明。

Shiva, I think there is some gap in your understanding of what traversal is about. Let me explain.

You can add any number of Item (s) to Form. The framework manages the following for all Item(s) built-in into MIDP

  1. Positioning and rendering of all Item(s)
  2. Scrolling, when there are more number of items that can fit in the screen.
  3. Handling screen commands and Item commands.

But when you extend CustomItem and implement your own item, complete control lies within the implementation. Consider a case where a Form contains a TextField and CustomItemImpl and you would want to toggle between TextField and CustomItemImpl. Since key handling, command handling and rendering is all in the control of CustomItemImpl, there must be a way in which framework must know when you want the TextField to have control and when the control needs to be passed on to CustomItemImpl.

Here is where traverse() method in CustomItem steps in. You return false when you are done with rendering and capturing data in CustomItemImpl and return true when you want to retain the control within the CustomItemImpl.

Let me elaborate further. Suppose you are implementing a TreeItem. When the focus is on TreeItem, you would like to do the following:

  1. Select a node
  2. Expand or Collapse nodes
  3. Navigate the nodes

All the above functionality forms part of your TreeItem implementation. However when you move KEY_UP past the fist node of the tree or KEY_DOWN past the last node of the tree, you would like to move over to TextField / any other item adjacent to this TreeItem. The way in which you let the framework know your intention is

  1. Return false in traverse() method when KEY_UP is selected while focus is on first node of the tree
  2. Return false in traverse() method when KEY_DOWN is selected while the focus is on last node of the tree.

Hope this clarifies your query. I would strongly suggest you to have a look at this particular example for more concrete illustration.

末が日狂欢 2024-10-12 23:41:38

我找到了解决方案。它对我有用。

正确的解决方案查找CustomItem遍历是由设备调用类“javax.microedition.lcdui.CustomItem”的方法“getInteractionModes()”支持的。

下面给出了代码片段

int supported_interaction_modes=this.getInteractionModes();
boolean horizontal__interaction,vertical_interaction;
if((supported_interaction_modes&CustomItem.TRAVERSE_HORIZONTAL)!=0)        //Horizontal traverse support
  horizontal_interaction=true;
else
  horizontal_interaction=false;
if((supported_interaction_modes&CustomItem.TRAVERSE_VERTICAL)!=0)
  vertical_interaction=true;        
else
  vertical_interaction=false;

,在上面的代码片段中,“this”指的是从“javax.microedition.lcdui.CustomItem”派生的类的对象

I find the solution. It's working for me.

The correct solution Finding the CustomItem traversal is supported by the device calling the method "getInteractionModes()" of the class "javax.microedition.lcdui.CustomItem".

Code snippet is given below

int supported_interaction_modes=this.getInteractionModes();
boolean horizontal__interaction,vertical_interaction;
if((supported_interaction_modes&CustomItem.TRAVERSE_HORIZONTAL)!=0)        //Horizontal traverse support
  horizontal_interaction=true;
else
  horizontal_interaction=false;
if((supported_interaction_modes&CustomItem.TRAVERSE_VERTICAL)!=0)
  vertical_interaction=true;        
else
  vertical_interaction=false;

in the above code snippet the "this" refers to the object of the class which is derived from "javax.microedition.lcdui.CustomItem"

旧时模样 2024-10-12 23:41:38
boolean isCustomItemSupported;
try {
    Class.forName("javax.microedition.lcdui.CustomItem");
    isCustomItemSupported = true;
} catch (Exception e) {
     isCustomItemSupported = false;
}
boolean isCustomItemSupported;
try {
    Class.forName("javax.microedition.lcdui.CustomItem");
    isCustomItemSupported = true;
} catch (Exception e) {
     isCustomItemSupported = false;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文