日期:2014-05-20  浏览次数:20708 次

编辑框内输入时,如何使其他文本作相应变化?
编辑框内输入时,如何使其他文本作相应变化?

------解决方案--------------------
form1.test11.value=form1.test2.value
------解决方案--------------------
使用ItemStateListener可以实现该功能
------解决方案--------------------

public class TextFieldWithItemStateListenerMIDlet extends MIDlet implements
ItemStateListener {
private Display display;

public TextFieldWithItemStateListenerMIDlet() {
display = Display.getDisplay(this);
}

TextField name;

TextField tel;

TextField summary;

public void startApp() {
Form f = new Form( "TextField 测试 ");
name = new TextField( "姓名 ", " ", 8, TextField.ANY);
tel = new TextField( "电话 ", " ", 14, TextField.PHONENUMBER);
summary = new TextField( "总结 ", " ", 30, TextField.UNEDITABLE);
f.append(name);
f.append(tel);
f.append(summary);
f.setItemStateListener(this);
display.setCurrent(f);
}

public void itemStateChanged(Item item) {
if (item == name) {
summary.setString( "输入的姓名为: " + name.getString());
} else if (item == tel) {
summary.setString( "输入的电话为: " + tel.getString());
} else {
summary.setString( " ");
}
}

public void pauseApp() {
}

public void destroyApp(boolean unconditional) {
}
------解决方案--------------------
ItemStateListener
------解决方案--------------------
使用ItemStateListener