Frage

I am making an application using LWUIT.

  1. There is a form

  2. There is a list embedded on the form.

  3. The list has 5 elements.

  4. Initially, when I first load the app, if I choose the 1st element, 2nd gets chosen; when I choose the second the 3rd gets chose and and so on (Weird!)

  5. I am not able to click any button on the screen either

  6. next what I do is, shift to a different from using arrow keys (of the keyboard... I am running the app on a simulator btw)

  7. Then I come back to the first form and now everything works as expected(no weird behaviour).

  8. What could be the issue?

  9. I am using Sun Java Micro Edition SDK 3.0 (default touch screen for testing)

My code is:

List dummy = new List();
        dummy.addItem("wewerwer");
        dummy.addItem("wewerdswer");
        dummy.addItem("wewqweerwer");
        dummy.addItem("dscxwewerwer");
        dummy.addItem("jhgwewerwer");
        mainListForm.setLayout(new BorderLayout());
        mainListForm.addComponent(BorderLayout.CENTER,dummy);
   mainListForm.show();

What could possible be going wrong here?

UPDATE 1

I think there is a bug here. I have attached the complete code below along with the screen shot

import javax.microedition.midlet.*;

import com.sun.lwuit.*;
import com.sun.lwuit.events.*;
import com.sun.lwuit.plaf.UIManager;
import com.sun.lwuit.util.Resources;

public class Demo extends MIDlet implements ActionListener {

  private Form mForm;
List abc;
  public void startApp() {

      Display.init(this);

      try {
Resources r = Resources.open("/Test.res");
UIManager.getInstance().setThemeProps(r.getTheme(
r.getThemeResourceNames()[0])
);
} catch (Exception e){
System.out.println(e.toString());
}

    if (mForm == null) {
      Button click = new Button("Press me!");

      click.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent ae) {
                   System.out.println("I have been pressed");
                }
            });
       abc = new List();
      abc.addItem("Str1");
      abc.addItem("Str2");
      abc.addItem("Str3");
      abc.addItem("Str4");
      abc.addItem("Str5");
      abc.addItem("Str6");



      Form f = new Form("Hello, LWUIT!");
      abc.addActionListener(this);
       f.addComponent(abc);
      Command exitCommand = new Command("Exit");
      f.addCommand(exitCommand);
      f.addCommandListener(this);
      f.addComponent(click);
      f.show();
    }
  }

  public void pauseApp() {
  }

  public void destroyApp(boolean unconditional) {
  }

  public void actionPerformed(ActionEvent ae) {
      System.out.println(abc.getSelectedIndex());

  }
}

enter image description here

So now when I click on 'Str1' of the list Str2 gets selected and so on.

IDE: Netbeans Emulator: Default Touch screen phone

War es hilfreich?

Lösung 2

OK....so this is how you resolve it.

After the form is displayed remove the list from the form and again add it to the form and then repaint the form.

Earlier Code

1) form.addComponenet(BorderLayout.center,list); 2) form.show();

Word Around for the problem

1)form.addComponenet(BorderLayout.center,list); 2)form.show(); 3)form.setScrollable(false);

I know its kind of strange, but this way the list index selection works smooth for touch screen phones.

Andere Tipps

On the action event set the list to active again after the event by invoking setHandlesInput(true)

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top