往Alert中添加Command

} catch (IOException e) {
	Alert alert = new Alert("地图; IOException", "网络连接捕获住异常:" + e.toString() + "\n\n" + "程序在10秒后会自动退出", null, AlertType.WARNING);
	final Command exitCommand = new Command("退出", Command.EXIT, 1);
	alert.addCommand(exitCommand);
	alert.setTimeout(10 * 1000);
	alert.setCommandListener(new CommandListener() {
		public void commandAction(Command c, Displayable d) {
			if (exitCommand == c) {
				dispatcher.exit(true);
			}
		}
	});
	dispatcher.display.setCurrent(alert);
}

  这一段代码如果没有alert.setTimeout(10*1000)这条语句,不经点击exitCommand按钮,程序会自动执行dispatcher.exit(true); 纠结了一个上午,解释如下:

 

When it is created, an Alert implicitly has the special Command DISMISS_COMMAND present on it. If the application adds any other Commands to the Alert, DISMISS_COMMAND is implicitly removed. If the application removes all other Commands, DISMISS_COMMAND is implicitly restored. Attempts to add or remove DISMISS_COMMAND explicitly are ignored. Thus, there is always at least one Command present on an Alert.
If there are two or more Commands present on the Alert, it is automatically turned into a modal Alert, and the timeout value is always FOREVER. The Alert remains on the display until a Command is invoked. If the Alert has one Command (whether it is DISMISS_COMMAND or it is one provided by the application), the Alert may have the timed behavior as described above. When a timeout occurs, the effect is the same as if the user had invoked the Command explicitly.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值