StringItem都响应按键,按键后能获取各自的内容,怎么做
我想让每个StringItem都响应按键,按键后能获取各自的内容,怎么做,下面做法无论按哪个item每次打印出来都是2,因为最后一次new的就是2。
大家看看怎么实现,帮帮忙。
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class Item extends MIDlet implements ItemCommandListener
{
private Display display;
private Command CMD_GO = new Command("Go", Command.ITEM, 1);
private StringItem strItem;
private Form form;
public Item()
{
super();
display = Display.getDisplay(this);
form = new Form("");
for(int i=0;i<3;i++)
{
strItem = new StringItem("", Integer.toString(i), javax.microedition.lcdui.Item.HYPERLINK);
strItem.setDefaultCommand(CMD_GO);
strItem.setItemCommandListener(this);
form.append(strItem);
}
display.setCurrent(form);
}
public void commandAction(Command c, javax.microedition.lcdui.Item item)
{
if (c == CMD_GO)
{
System.out.println(strItem.getText());
}
}
protected void startApp() throws MIDletStateChangeException
{
}
protected void pauseApp()
{
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException
{
}
}