Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/207.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android PhoneGap框架中navigator.notification.confirm中按钮的顺序_Android_Iphone_Cordova_Phonegap Plugins - Fatal编程技术网

Android PhoneGap框架中navigator.notification.confirm中按钮的顺序

Android PhoneGap框架中navigator.notification.confirm中按钮的顺序,android,iphone,cordova,phonegap-plugins,Android,Iphone,Cordova,Phonegap Plugins,我正在PhoneGap应用程序中使用以下代码 function registrationCallBack(button){ if(button == 2) { window.location.href = "login.html"; } } navigator.notification.confirm("Are you sure ?", registrationCallBack

我正在PhoneGap应用程序中使用以下代码

        function registrationCallBack(button){
            if(button == 2) {
                window.location.href = "login.html";
            }
        }

   navigator.notification.confirm("Are you sure ?", registrationCallBack, "Confirmation", "Cancel, Ok");
在iPhone中,按钮的顺序是“取消”和“确定”。 但对于Android来说,按钮的顺序是相反的。先是“Ok”,然后是“Cancel”

因此,回调方法中的按钮索引会发生更改

欢迎所有建议:)


谢谢,

尝试使用以下解决方案:

function showConfirm(message, callback, buttonLabels, title){

    //Set default values if not specified by the user.
    buttonLabels = buttonLabels || 'OK,Cancel';

    title = title || "default title";

    //Use Cordova version of the confirm box if possible.
    if(navigator.notification && navigator.notification.confirm){

            var _callback = function(index){
                if(callback){
                    callback(index == 1);
                }
            };

            navigator.notification.confirm(
                message,      // message
                _callback,    // callback
                title,        // title
                buttonLabels  // buttonName
            );

    //Default to the usual JS confirm method.
    }else{
        invoke(callback, confirm(message));
    }
}
下面是您将如何使用它:

var message = "Would you like to proceed?";
var title = "Important Question";

//The first element of this list is the label for positive 
//confirmation i.e. Yes, OK, Proceed.
var buttonLabels = "Yes,No";

var callback = function(yes){
    if(yes){
        alert('Proceed');
    }else{
        alert('Do Not Proceed'); 
    }
};

showConfirm(message, callback, buttonLabels, title);

我还没有在iphone上尝试过这个。但我已经在android上尝试过了。我在phonegap 1.4.1中没有遇到任何这样的问题。因此,我建议您升级phonegap版本。您面临的问题可能会在新版本中得到修复。:)

这不是问题。您得到的是各自平台的本机行为。在iOS中,“取消””按钮将出现在左侧,而在Android中,您将在右侧看到它。如果问题只是按钮索引,那么您可以在代码中处理它。但您无法更改屏幕上按钮的顺序。

我有点晚了,但我遇到了相同的问题,但我所做的是更改它们,使“取消”转到“确定”的位置,“确定”转到“取消”的位置。这对我来说很有效。

根据Android big brains的说法,我创建了一个bug来跟踪它,这是一个“功能”而不是bug。你可能不想“修复”它,因为用户希望在特定平台上的某些地方有按钮。你能解释一下
var\u callback=function(index){if(callback){callback(index==1);}};
是否总是将1返回回调函数?to callback将按钮索引转换为布尔值。例如,yes按钮位于索引1中,因此当用户点击yes按钮时,
index==1
等于
true
等。