1
請看下面的代碼。確定按鈕不起作用
在這裏,「確定」按鈕沒有響應。
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class TexyFieldExample extends MIDlet implements CommandListener
{
private Form form;
private Display display;
private TextField name, company;
private Command ok;
public TexyFieldExample()
{
name = new TextField("Name","",30,TextField.ANY);
company = new TextField("Company","",30,TextField.ANY);
ok = new Command("OK",Command.OK,2);
}
public void startApp()
{
form = new Form("Text Field Example");
display = Display.getDisplay(this);
form.append(name);
form.append(company);
form.addCommand(ok);
display.setCurrent(form);
}
public void pauseApp()
{
}
public void destroyApp(boolean destroy)
{
notifyDestroyed();
}
public void commandAction(Command c, Displayable d)
{
String label = c.getLabel();
if(label.equals("ok"))
{
showInput();
}
}
private void showInput()
{
form = new Form("Input Data");
display = Display.getDisplay(this);
form.append(name.getString());
form.append(company.getString());
display.setCurrent(form);
}
}
更具體地說,他需要執行'ok.setCommandListener(this);'來獲得他想要的行爲。 – kurtzbot 2012-08-03 16:13:24
非常感謝您的回答!有效!謝謝:) – 2012-08-04 14:01:59
@kurtzbot:ok按鈕沒有這樣的方法。我檢查了。 – 2012-08-04 14:03:30