I was using Android 4.0.3+JQM+Phonegap without having troubles. Yesterday I tested on Android 4.1 and found that those dynamically generated ListView would sometimes give me duplicated results. For example, I use the following code to generate a ListView to show today’s date:
<ul data-role="listview" data-inset="true" data-theme="c"
data-divider-theme="d" id="todayvalue">
</ul>
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
var today = new Date();
var dayofmonth = today.getDate();
var dayofweek = today.getDay();
var year = today.getFullYear();
var month = today.getMonth();
var myDays= ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"];
var m_names = ["January", "February", "March",
"April", "May", "June", "July", "August", "September",
"October", "November", "December"];
$('#todayvalue').append('<li>Today is '+ myDays[dayofweek]+ ', '+year+'-'+m_names[month]+'-'+dayofmonth+'</li>');
$('#todayvalue').listview('refresh');
}
It used to have no problem at all. But now it would generate two identical rows.
Whom to blame?
Update: I have uploaded the project to https://github.com/ysongfinance/520Toll.
After further debugging, I found that onDeviceReady() was called twice but one of them looks weird:
07-05 20:42:31.368: I/Web Console(825): ########in OndeviceReady at file:///android_asset/www/js/updatetoll.js:4
07-05 20:42:31.488: I/Web Console(825): ########in OndeviceReady at null:4
Look at the second call “in OndeviceReady at null”, what does that “null” suppose to mean?
I tried your example with Cordova 1.9 and Android 2.2 and it was firing
devicereadytwice.Then I moved the
updatetoll.jsincluded in body to head and it fires only once.Can you check this change and see does it work in your device.
Edit
jQuery Mobile seems to create the problem if you put the listener outside of the
headtag. I tried the newer version of jQuery Mobile (1.1.0) but the affect is still the same.If you remove the jQuery Mobile and keep your code as it is then it will fire only once.