开发者

Checking the CustomItem in j2me support traversal or not

Checking the CustomItem in j2me support traversal or not?

How sh开发者_如何学编程ould I check the CustomItem in j2me support traversal or not?


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.


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"


boolean isCustomItemSupported;
try {
    Class.forName("javax.microedition.lcdui.CustomItem");
    isCustomItemSupported = true;
} catch (Exception e) {
     isCustomItemSupported = false;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜