我管理了取消事件,稍微修改了 .java 插件:在代码之后
public void run() {
final DateSetListener dateSetListener = new DateSetListener(datePickerPlugin, callBackId);
final DatePickerDialog dateDialog = new DatePickerDialog(currentCtx, dateSetListener, mYear,mMonth, mDay);
我添加了事件来捕获取消:
dateDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int which)
{
if (which == DialogInterface.BUTTON_NEGATIVE) {
datePickerPlugin.success(new PluginResult(PluginResult.Status.NO_RESULT, ""), callBackId);}}});
当按下取消按钮时,这会将日期设置为“”。在 javascript 代码中,我设法将焦点事件更改为点击事件,如下所示(我在移动设备上使用具有 TAP 事件的插件:
$('.nativedatepicker').bind('tap',function(event) {
var currentField = $(this);
console.log(currentField.val());
var myNewDate = Date.parse(currentField.val()) || new Date();
if(typeof myNewDate === "number"){ myNewDate = new Date (myNewDate); }
//myNewDate = currentField.val();
console.log("inside native date picker " + event);
// Same handling for iPhone and Android
window.plugins.datePicker.show({
date : myNewDate,
mode : 'date', // date or time or blank for both
allowOldDates : true
}, function(returnDate) {
console.log("ret date" + returnDate);
if (returnDate)
{
var newDate = new Date(returnDate);
currentField.val(returnDate);
// This fixes the problem you mention at the bottom of this script with it not working a second/third time around, because it is in focus.
currentField.blur();
}
});
});
我希望能有所帮助。