具有Contentview的自定义对话框,该视图的布局包含2个按钮-Listener



从列表视图中,我打开了一个警报对话框(3个选项和2个按钮)

我有这个:

                LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);// ass
            inflater = getLayoutInflater();
            View layout = inflater.inflate(R.layout.custom_dialog,null);
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setView(layout);
            builder.setTitle("Select");
            builder.setCancelable(true);
            builder.setSingleChoiceItems(tonos, -1,new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int item) {
                    Log.d(TAG, "Option: " + tonos[item]);
                    tone=tonos[item];

                    Button botonOK = (Button) findViewById(R.id.botOK);
                    try {
                        botonOK.setOnClickListener(new OnClickListener() {
                            public void onClick(View v) {
                                Log.d(TAG,"button ok");
                                }
                            });
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        Log.d(TAG, "Exception " + e);
                    }

                }
            });

            alert = builder.create();
            alert.show();


    }

第二个onClick的参数正确吗?我正在疯狂地测试,但我找不到解决方案。

        LayoutInflater inflater = getLayoutInflater();
        View layout = inflater.inflate(R.layout.custom_dialog,null);
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        Button botonOK = (Button) layout.findViewById(R.id.botOK);
        botonOK.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                Log.d(TAG,"button ok");
            }
        });
        builder.setView(layout);
        builder.setTitle("Select");
        builder.setCancelable(true);
        builder.setSingleChoiceItems(tonos, -1,new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int item) {
                Log.d(TAG, "Option: " + tonos[item]);
                tone=tonos[item];
            }
        });
        alert = builder.create();
        alert.show();

最新更新