0

Checking the CustomItem in j2me support traversal or not?

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

gnat
  • 6,213
  • 108
  • 53
  • 73
SIVAKUMAR.J
  • 4,258
  • 9
  • 45
  • 80

3 Answers3

1

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.

Kiran Kuppa
  • 1,457
  • 10
  • 18
  • Thanks for your kind information.But ur answer is not clear & simple.I cannot understand ,it is confusing me.Please make it as much as simple,as much as clear,as much as understandable format. – SIVAKUMAR.J Dec 07 '10 at 07:15
  • Let me try to make it simple. CustomItem will be embedded in the Form. But painting and event handling is NOT done by Form, but CustomItem. Consider that Form contains a TextField and CustomItem. And the user would be using Key up and key down to select either TextField or Form. Unless CustomItem tells the Form that it has done it's job, Form will NOT know to move your key events to TextField. So, when you return false in traverse method, Form will know that CustomItem is done with it's job and moves the focus to TextField. – Kiran Kuppa Dec 07 '10 at 07:18
  • Referring to your original question, traversal is SUPPORTED by ALL MIDP 2.0 j2me implementations. – Kiran Kuppa Dec 07 '10 at 07:25
0

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"

gnat
  • 6,213
  • 108
  • 53
  • 73
SIVAKUMAR.J
  • 4,258
  • 9
  • 45
  • 80
-1
boolean isCustomItemSupported;
try {
    Class.forName("javax.microedition.lcdui.CustomItem");
    isCustomItemSupported = true;
} catch (Exception e) {
     isCustomItemSupported = false;
}
oxigen
  • 6,263
  • 3
  • 28
  • 37
  • Hi oxigen, Thanks for ur kind reply.I also want to check the treversing in CustomItem is allowed or not.How to do it? – SIVAKUMAR.J Dec 04 '10 at 04:30
  • 2
    This isn't the answer to the question. This merely checks if CustomItem is available on the phone or not. This would at best tell the application if the platform is MIDP 2.0 or not! – Kiran Kuppa Dec 04 '10 at 06:12