若是把Alert跟Command事件绑定的话,Alert就不会自动消失,调用SetTimeout也不行。
因为Alert中已经自动定义了DISMISS_COMMAND
事件,如果再跟其他Command事件绑定的话,事件DISMISS_COMMAND
就会自动消失(即Alert不会自动消失)。
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.TextBox;
import javax.microedition.lcdui.TextField;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class MIDLet8 extends MIDlet{
private Display dis;
private Alert alt=null;
private TextBox tbx=new TextBox("请输入短信内容:","",255,TextField.ANY);
private Command CmdDeleteText = new Command("删除文本", Command.SCREEN, 1);
public MIDLet8(){
Image img=null;
try{
img=Image.createImage("/APIs.png");
}catch(Exception ex){
ex.printStackTrace();
}
alt=new Alert("我的提示:","请注意",img,AlertType.INFO);
}
protected void startApp() throws MIDletStateChangeException {
dis = Display.getDisplay(this);
dis.setCurrent(alt,tbx);
//添加Command后alert会自动绑定事件
//alt.addCommand(CmdDeleteText);
//注册监听器后alert就不会自动消失了
//alt.setCommandListener(this);
alt.setTimeout(Alert.FOREVER);
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
}
protected void pauseApp() {
}
}
该例子可以看出来。