0

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

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

4

3 回答 3

1

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 时,在 traverse() 方法中返回 false
  2. 当焦点位于树的最后一个节点上时选择 KEY_DOWN 时,在 traverse() 方法中返回 false。

希望这可以澄清您的查询。我强烈建议您查看这个特定示例以获得更具体的说明。

于 2010-12-05T04:06:20.000 回答
0

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

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"

于 2010-12-14T11:01:16.110 回答
-1
boolean isCustomItemSupported;
try {
    Class.forName("javax.microedition.lcdui.CustomItem");
    isCustomItemSupported = true;
} catch (Exception e) {
     isCustomItemSupported = false;
}
于 2010-12-03T14:03:13.947 回答