我正在使用 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();
}
}
最佳答案
如果您想在电话拨号中显示号码,只需执行以下操作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);
}
}
关于java - 如何为通话功能创建确认对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19279789/