Search code examples
java-memidplcdui

Create Form in J2ME


I want to design one form that contains TextField and ListView in J2ME. But I don't know how to create this form. It is looked like Dictionary Form. Could anybody help me to do that?


Solution

  • You can't really do that with the basic UI controls in MIDP.

    List can't contain TextField.

    I would suggest looking at LWUIT since it has better controls.

    Otherwise, if you don't need to display Images in your List, then you can use a Form containing both TextField and StringItem. Unfortunately, an ItemStateListener added to the Form will probably not give you as much information as a List.

    Implementing the list yourself in a CustomItem means writing quite a bit of code but is doable.

    If what you need is a TextField where you enter a search String and a List that displays the search result, I suggest using a TextBox first, then a List. Separate screens are by far the quickest solution here.

    Edit: you can't use swing in j2me. what you can do is have just a textfield in a form, then add/remove StringItems to/from the Form when the user changes the content of the TextField. You should be able to rely on ItemStateListener to tell you when the textfield content changes.