0

我正在使用 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();
}

}

4

2 回答 2

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);
}

}
于 2013-10-09T18:45:23.883 回答
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();
 }`
于 2013-10-09T18:52:53.563 回答