存储textField中的值

时间:2017-12-10 07:20:54

标签: java forms java-me

如何存储在表单文本字段中输入的值并将这些输入的值显示在另一个表单中?我正在使用java-me。我试图使用dbhelper但我无法理解它。一段代码会有所帮助。我该怎么办?任何帮助或积极的评论将不胜感激。

这是我的代码:

public class Song extends Form implements CommandListener {
    private Display display;
    private List list;
    private final Command logout;
    private Command back;
    private final TextField songname;
    private TextField band;
    private final MIDlet midlet;
    private Command add;
    private Form form;
    private DbHelper dbhelper1;

    public Song(MIDlet midlet) {
        super("My Playlist");

        songname = new TextField("Song name: ", null, 20, TextField.ANY);
        band = new TextField("Singer/Band Name: ", null, 20, TextField.ANY);
        form = new Form("New form");
        logout = new Command("Logout", Command.OK, 0);
        add = new Command("Add", Command.OK, 0);
        back = new Command("Back", Command.BACK, 0);
        this.append(songname);
        this.append(band);
        this.addCommand(logout);
        this.addCommand(add);
        this.addCommand(back);
        this.setCommandListener(this);
        this.midlet = midlet;
    }

    public void startApp() {
        this.append("This is MainForm");
        display.setCurrent(this);
    }

    public void showInput() {
        String w = "by";
        String n = songname.getString();
        String c = band.getString();
        Form form = new Form("Input Value");
        this.append(n);
        this.append(w);
        this.append(c);
        System.out.print("\n");
        display.setCurrent(form);
    }

    public void commandAction(Command c, Displayable d) {

        if (c == logout) {
            Display.getDisplay(midlet).setCurrent(new LoginForm(midlet));
        }
        if (c == add) {
            showInput();
        }
        if (c == back) {
            Display.getDisplay(midlet).setCurrent(new Playlist(midlet));
        }
    }
}

1 个答案:

答案 0 :(得分:0)

您必须执行获取TextField表单并将其更改为新表单的函数。 我不知道你的表格是什么,但你可以很容易地把它改成字符串。 像这样的事情:

public Form ChangeForm(TextField s) {

    String str = s.getText() // get string from textfield
    // Setting new form..
    // return form
}