1

从列表视图中,我打开一个警报对话框(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 的论点是否正确?我正在疯狂测试,但我没有找到解决方案。

4

1 回答 1

2
        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();
于 2012-09-12T07:15:43.177 回答