以下是引用marer在2007-2-15 22:34:23的发言:
我写了个简单的程序,为什么装到Nokia3230机上运行出问题?
程序要求点击下拉框中的值时,将相应的值显示在文本框中.
问题是:无论选择下拉框中的哪个值,文本框中都没有反应.根本没有执行ItemStateChanged方法
哪位大侠可以解决?多谢了!
程序如下:
public class ItemStateDemo extends MIDlet implements CommandListener,ItemStateListener
{
private Form main=null;
private Display mydis=null;
private ChoiceGroup cgInfo=null;
private TextField txtInfo=null;
private Command cmdExit=null;
public void startApp()
{
main=new Form("Demo");
cgInfo=new ChoiceGroup("select:",ChoiceGroup.POPUP);
cgInfo.append("",null);
cgInfo.append("A",null);
cgInfo.append("B",null);
txtInfo=new TextField("","",10,TextField.ANY);
cmdExit=new Command("Exit",Command.EXIT,1);
main.append(cgInfo);
main.append(txtInfo);
main.addCommand(cmdExit);
main.setCommandListener(this);
main.setItemStateListener(this);
mydis=Display.getDisplay(this);
mydis.setCurrent(main);
}
public void pauseApp()
{
}
public void destroyApp(boolean u)
{
}
public void commandAction(Command c,Displayable d)
{
if(c==cmdExit)
{
destroyApp(true);
notifyDestroyed();
}
}
public void ItemStateChanged(Item item)//这里的i应该是小写,JAVA里面的方法名,第一个字母一般都是小写
{
if(item==cgInfo)
{
this.txtInfo.setString(this.cgInfo.getString(this.cgInfo.getSelectedIndex()));//这里小了一个括号
}
}
}
你的程序有两个错误,以现在的程序来看,是连编译都通过不了的
如果你把以前两点改过来以后就可以了,我这里运行没问题