phonegap で開発されたアプリがあります。
遅い日付ピッカー プラグインを使用していたので、変更したいと思いました。
使えるものを探して見つけます。
https://github.com/phonegap/phonegap-plugins/tree/master/Android/DatePicker
私は手順に従いました。
しかし、日付ピッカーが表示されず、空の入力要素しか表示されません。
パッケージ「com.phonegap.plugin」を作成し、「DatePickerPlugin.java」をこのパッケージに入れました。
「datePickerPlugin.js」を作成し、assets/www ファイルの下に置きます。
index.htmlに含めました
<script type="text/javascript" charset="utf-8" src="datePickerPlugin.js"></script>
また
<script type="text/javascript" src="datePickerPlugin.js"></script>
要素に class="nativedatepicker" を追加しました
<input type="text" class="nativedatepicker" id="get_date" name="get_date" />
コードを index.html のスクリプト部分に配置します
$('.nativedatepicker').focus(function(event) {
var currentField = $(this);
var myNewDate = Date.parse(currentField.val()) || new Date();
// 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) {
var newDate = new Date(returnDate);
currentField.val(newDate.toString("dd/MMM/yyyy"));
// 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();
});
});
$('.nativetimepicker').focus(function(event) {
var currentField = $(this);
var time = currentField.val();
var myNewTime = new Date();
myNewTime.setHours(time.substr(0, 2));
myNewTime.setMinutes(time.substr(3, 2));
// Same handling for iPhone and Android
plugins.datePicker.show({
date : myNewTime,
mode : 'time', // date or time or blank for both
allowOldDates : true
}, function(returnDate) {
// returnDate is generated by .toLocaleString() in Java so it will be relative to the current time zone
var newDate = new Date(returnDate);
currentField.val(newDate.toString("HH:mm"));
currentField.blur();
});
});
最後に、プラグインを plugins.xml に配置します。
<plugin name="DatePickerPlugin" value="com.phonegap.plugin.DatePickerPlugin"/>
私のエラーはどこですか?
私は cordova-1.9.0 と Android 2.2 を使用しています。また、Cordova ライブラリ ファイルも含めました。
このエラーに関するすべての質問をstackoverflowでほぼ調べましたが、効率的な解決策は見つかりませんでした。