如何为呼叫功能创建确认对话框

时间:2013-10-09 18:26:01

标签: java android xml dialog phone-call

我正在使用eclipse进行Android应用程序开发,我想创建一个对话框,以便在从应用程序的按钮触发调用函数时进行确认。

例如,当我按下按钮时,我想要一个对话框你确定要继续吗?是和否。

现在,当我按下按钮进行通话时,它会直接自动拨号(没有拨号盘)

(我不确定此代码是否对此负责)

public class AlertDialogManager {
/**
 * Function to display simple Alert Dialog
 * @param context - application context
 * @param title - alert dialog title
 * @param message - alert message
 * @param status - success/failure (used to set icon)
 *               - pass null if you don't want icon
 * */
public void showAlertDialog(Context context, String title, String message,
        Boolean status) {
    AlertDialog alertDialog = new AlertDialog.Builder(context).create();

    alertDialog.setTitle("Title");
    alertDialog.setMessage("Message");
    alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
      public void onClick(DialogInterface dialog, int which) {
        }
    });

    // Showing Alert Message
    alertDialog.setIcon(R.drawable.icon);
    alertDialog.show();
}

}

2 个答案:

答案 0 :(得分:1)

如果您想在电话拨号中显示号码,请执行此操作Intent intent = new Intent(Intent.ACTION_DIAL);

public class AlertDialogManager {
/**
 * Function to display simple Alert Dialog
 * @param context - application context
 * @param title - alert dialog title
 * @param message - alert message
 * @param status - success/failure (used to set icon)
 *               - pass null if you don't want icon
 * */
public void showAlertDialog(Context context, String title, String message,
        Boolean status) {
    AlertDialog alertDialog = new AlertDialog.Builder(context).create();

    alertDialog.setTitle("Title");
    alertDialog.setMessage("Message");
    alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
      public void onClick(DialogInterface dialog, int which) {
          makeCall("12345");  //phone number you want to dial

        }
    });

    // Showing Alert Message
    alertDialog.setIcon(R.drawable.icon);
    alertDialog.show();
}

private void makeCall(String phone){
    Intent intent = new Intent(Intent.ACTION_DIAL);
    intent.setData(Uri.parse("tel:"+phone));
    startActivity(intent);
}

}

答案 1 :(得分:0)

如果我理解正确你应该实现这样的事情:

public void btnClick(View v) {

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage("Are you sure you want to proceed?");
    builder.setCancelable(false);

    builder.setPositiveButton("YES", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
            callFunction(); // THE FUNCT THAT YOU WANNA CALL
        }
    });

    builder.setNegativeButton("NO", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    builder.show();
 }`