0

我试图让用户单击我的呼叫按钮,然后打开一个带有 2 个选项(呼叫和取消按钮)的警报对话框,我试图实现一些代码但抛出异常。我知道很模糊,但为了简单起见,我如何使用alerdialog实现我的目标

        @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        if ((getArguments().getInt(ARG_SECTION_NUMBER)==1)) {
            View view = inflater.inflate(R.layout.phones, container, false);

            //button decloration
            Button newPage = (Button)view.findViewById(R.id.view3);
            newPage.setOnClickListener(new View.OnClickListener() {
                @Override public void onClick(View v) { Intent callIntent = new Intent(Intent.ACTION_DIAL);
                    callIntent.setData(Uri.parse("tel:07**********"));




                    startActivity(callIntent);                }

            });
            return view;

        }
4

1 回答 1

0

将以下代码放入一个方法中,并根据需要调用该方法。

AlertDialog alertDialog;

    AlertDialog.Builder builder = new AlertDialog.Builder(BaseActivity.this);
        alertDialog = builder.create();
        alertDialog.setOnDismissListener(new myOnDismissListener());

        alertDialog.setTitle("TITLE");
        alertDialog.setMessage("Are you sure to call ?");
        alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                                //PUT YOUR CALL PHONE CODE HERE

            }
        });
        alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE,"Cancel", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
            }

        });
        alertDialog.show();

    }

    class myOnDismissListener implements DialogInterface.OnDismissListener {

        @Override
        public void onDismiss(DialogInterface dialog) {
            // TODO Auto-generated method stub
            alertDialog.dismiss();
        }
    }
于 2013-09-23T12:31:11.907 回答