我是靠谱客的博主 美满学姐,最近开发中收集的这篇文章主要介绍往Alert中添加Command,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

} catch (IOException e) {
Alert alert = new Alert("地图; IOException", "网络连接捕获住异常:" + e.toString() + "nn" + "程序在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.

最后

以上就是美满学姐为你收集整理的往Alert中添加Command的全部内容,希望文章能够帮你解决往Alert中添加Command所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(39)

评论列表共有 0 条评论

立即
投稿
返回
顶部