Skip to main content

how to handle list event in LWUit

1 reply [Last post]
iraqy2010
Offline
Joined: 2011-02-09
Points: 0

hi all
i am new in LWUIT
I want to write pro. contain list and from list i can entering to any form
the follwing prog. not worked to entering and backing to form of list
it can enter just one form
pleas any one help me and edit on my code

this my code

import com.sun.lwuit.*;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.events.ActionListener;

import javax.microedition.lcdui.Image.*;
import javax.microedition.midlet.MIDlet;

public class DemoDialog extends MIDlet implements ActionListener
{

public Form f1,f2,f3;
private List l;
private Button b,b1;
int x;

public void startApp()
{

Display.init(this);

f2=new Form("2");
f3=new Form("3");

f1=new Form("1");
b=new Button("back");
b1=new Button("back");

String[] items = { "Red", "Blue", "Green", "Yellow" };
l=new List(items);

f1.addComponent(l);
f1.getStyle().setBgColor(0xffffff);
f3.addComponent(b);
f2.addComponent(b1);

l.addActionListener(this);
l.getStyle().setBgColor(0xffffff);

x=l.getSelectedIndex();
f1.show();
}

public void pauseApp()
{
}
public void destroyApp(boolean unconditional)
{
}
//act on the command
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==l)

{
switch(x)
{
case 0:

{ f3.show();

break;}
case 1:
{ f3.show();
break;}
}

}
else
if(ae.getSource()==b||ae.getSource()==b1)

f1.show();

}

}

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
vprise
Offline
Joined: 2003-11-07
Points: 0

getSelectedIndex should work when the action actually happened not before the list was even shown.
May I suggest using a debugger in the future.