android - 如何在Android中单击Alert Box中的按钮时关闭应用程序?

标签 android onclick

如何在 onClick() 内关闭 Android 中的应用程序?

我的代码如下:

alertbox.setNegativeButton("No", new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface arg0, int arg1) {
        System.out.println("cancel clicked");  
    }
});   
alertbox.show();   

如果我在onClick内写入finish(),它没有帮助。

最佳答案

试试这个方法

alertbox.setNegativeButton("No", new DialogInterface.OnClickListener() {               
        public void onClick(DialogInterface arg0, int arg1) {        
            ActivityName.this.finish();
        }              
    });   
    alertbox.show();   
}

关于android - 如何在Android中单击Alert Box中的按钮时关闭应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7253782/

相关文章:

javascript - Javascript 中按钮消失

java - Lint 将 Kotlin MutableMap.forEach() 视为 java.util.Map.forEach()

android - 在 Xamarin Android 名称中绑定(bind)一个 .AAR 不存在

javascript - 使用 php 在 onclick 事件中提供变量

Javascript onclick 函数麻烦

javascript - 使用Chrome扩展解除绑定(bind)点击事件?

jquery - 首先设置一个事件链接css并动态更改它

java - 按钮导致致命异常 : main, 以及如何插入 "$"

java - Android 中的 SAX 解析问题...空元素?

android - Android ART 运行时是否具有与 Dalvik 相同的方法限制限制?