如何在Android中显示警告对话框? [英] how to display Alert Dialog in android?

查看:204
本文介绍了如何在Android中显示警告对话框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要显示对话框/弹出窗口的消息,用户,显示您确定要删除该条目?与删除一个按钮。在点击按钮删除,应该删除该条目,否则什么都没有。

I want to display dialog/popup window for message to user that shows "Are you sure you want to delete this entry?" with One button of 'Delete' . On click of button Delete, it should delete that entry otherwise nothing.

我已经写了这些按钮的点击监听,但我不知道如何调用对话框或弹出式和它的功能。

I have written a click listener of those buttons but I dont know how to invoke dialog or popup and its functionality.

推荐答案

您可以使用警报生成器这样的:

You could use the alert builder for this:

new AlertDialog.Builder(context)
    .setTitle("Delete entry")
    .setMessage("Are you sure you want to delete this entry?")
    .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) { 
            // continue with delete
        }
     })
    .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) { 
            // do nothing
        }
     })
    .setIcon(android.R.drawable.ic_dialog_alert)
     .show();

这篇关于如何在Android中显示警告对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆