【问题标题】:How to access the dialog button in the preference dialog如何访问首选项对话框中的对话框按钮
【发布时间】:2012-02-24 22:35:24
【问题描述】:

我创建了一个带有对话框的首选项活动。该对话框有两个按钮 CANCEL 和 ADD。单击添加按钮后,应打开另一个对话框,其中包含两个用于输入 MAC 地址和设备名称的编辑文本框

如何处理首选项屏幕对话框中按钮的单击。如果我可以访问对话框的点击,那么我可以打开另一个活动。

【问题讨论】:

    标签: android dialog


    【解决方案1】:

    您可以为对话框的每个默认按钮提供自己的DialogInterface.OnClickListener。这是 developer.android.com 上 Dialogs topic 的复制粘贴:

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage("Are you sure you want to exit?")
           .setCancelable(false)
           .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int id) {
                    MyActivity.this.finish();
               }
           })
           .setNegativeButton("No", new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
               }
           });
    AlertDialog alert = builder.create();
    

    您也可以create your own dialog, with a custom layout 显示您喜欢的任何小部件。使用这种方法,您可以将常规 View.OnClickListener 连接到按钮并将逻辑放入其中。

    【讨论】:

    • 会试试这个 thakyou 的回复
    猜你喜欢
    • 1970-01-01
    • 2014-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-27
    相关资源
    最近更新 更多