开发者

How to close application onClick of a button in Alert Box in Android?

How do I close the application in Android inside onClick()?

My code follows something like this:

alertbox.setNegativeButton("No", new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface arg0, int arg1) {
        System.out.println("cancel clicked");  
    }
});   
alertbox.show();   
开发者_如何学Python

If I write finish() inside onClick it did not help.


try this way

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


Try calling finish of the main activity directly. MainActivityName.this.finish();

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜