首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何从AlertDialog获取结果?

如何从AlertDialog获取结果?
EN

Stack Overflow用户
提问于 2011-05-11 01:01:04
回答 5查看 41.3K关注 0票数 25

我使用AlertDialog.Builder显示一个对话框,提示用户输入密码,然后希望将该密码保存在首选项中,但是我不知道如何从警报对话框的输入法获得结果。

以下是我希望能够做的事情:

    String result;
    AlertDialog.Builder b = new AlertDialog.Builder(this);
    b.setTitle("Please enter a password");
    final EditText input = new EditText(this);
    b.setView(input);
    b.setPositiveButton("OK", new DialogInterface.OnClickListener()
    {
        @Override
        public void onClick(DialogInterface dialog, int whichButton)
        {
           //I get a compile error here, it wants result to be final.
           result = input.getText().toString();
        }
    });
    b.setNegativeButton("CANCEL", null);
    b.create().show();

但是,我愿意做一些事情,比如showDialog(int);,然后使用onCreateDialog(int)方法,以某种方式设置结果并以其他方法接收结果,但我不知道如何处理最后一部分。

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5953644

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档