我的AlertDialog在哪里?

jac*_*nad 1 android android-alertdialog

我试图向Android OnClickListener添加一个是/否确认弹出窗口.可以在setOnClickListener中使用AlertDialog.Builder,还是应该采用不同的方法?我已经使用eclipse/android调试环境逐步完成了以下代码,并期望弹出窗口出现在.create,等待用户响应,但事实并非如此.我是android和java的新手,所以我可能会遗漏一些明显的东西.任何建议,想法或方向将不胜感激.

public class Controller extends Activity {
...
        buttonOn.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                new AlertDialog.Builder(Controller.this)
                    .setIcon(R.drawable.ic_menu_help)
                    .setMessage("Are You Sure?")
                    .setPositiveButton("OK", 
                            new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, 
                                int whichButton) {
                        // Positive response code
                    }
                })
                .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        // Negative response code
                    }
                })
                .create();
            }
        });
Run Code Online (Sandbox Code Playgroud)

Ric*_*ler 6

AlertDialog.Builder#show而不是create.create返回一个AlertDialog对象,但不显示它.