Phonegap android需要很长时间才能检测到点击事件
有很多关于删除移动应用程序中的点击延迟的文章。Fastclick关注的是这个问题:从点击按钮触发click事件开始,移动浏览器将等待大约300毫秒 但我的查询有点不同,我在eclipse中开发的android移动应用程序启用点击事件花费的时间太长,即应用程序第一次加载点击事件时,点击事件不会触发很长时间,一旦点击事件第一次发生,后续的点击事件会快得多。我只在模拟器上测试过它,还没有在真正的设备上测试过 我怎样才能消除这种延迟 这是我的html页面:Phonegap android需要很长时间才能检测到点击事件,android,jquery,jquery-mobile,cordova,Android,Jquery,Jquery Mobile,Cordova,有很多关于删除移动应用程序中的点击延迟的文章。Fastclick关注的是这个问题:从点击按钮触发click事件开始,移动浏览器将等待大约300毫秒 但我的查询有点不同,我在eclipse中开发的android移动应用程序启用点击事件花费的时间太长,即应用程序第一次加载点击事件时,点击事件不会触发很长时间,一旦点击事件第一次发生,后续的点击事件会快得多。我只在模拟器上测试过它,还没有在真正的设备上测试过 我怎样才能消除这种延迟 这是我的html页面: 我猜你的应用程序落后了。因为javascr
我猜你的应用程序落后了。因为javascript是单线程的,如果代码足够重,有时UI和其他事件会被阻塞。响应不需要一分钟,处理代码需要一分钟,然后当代码最终释放时,它将处理单击 问:如何确保情况属实 答:对您在onDeviceReady中调用的3个函数进行注释,只需创建一个触发警报或控制台日志的简单按钮。然后在同一设备/仿真器上运行它。 如果它工作正常,那么hyg,这是你的问题,你正在运行非常低效的代码 问:这是可行的,但如何解决效率问题 答:您正试图在同一时间运行大约3个循环,您真的需要这样做吗?它们有多大?它们能变小吗?你能加载sum,以后再加载其他的吗?可能会显示加载指示器,直到完成 问:那没有解决问题,现在怎么办
答:我想不出任何其他可能导致这种情况的原因,我们需要更多的信息,但你应该尝试在一台真正的设备上运行它,可能使用不同的android版本。奇怪的问题。不过,您可以尝试一下tap事件。我也尝试过使用tap事件。sameI也注意到了仿真器的类似问题。click事件无法正常触发并被卡住。需要点击两次以触发,然后事件触发两次。有时单击运行没有任何问题。但在我的情况下,第一次单击事件似乎需要大约1分钟才能触发,然后后续事件会更快。我知道模拟器很慢,会这么慢吗?
<head>
<title>First App</title>
<style>
.table {
border: 2px solid #a1a1a1;
background: #dddddd;
width: 90px;
height: 90px;
border-radius: 25px;
text-align: center;
line-height: 90px;
position:absolute;
}
</style>
<script src="cordova.js"></script>
<link rel="stylesheet" href="jquery.mobile-1.4.3.min.css">
<script type="text/javascript" src="jquery-1.11.1.min.js"></script>
<script src="jquery.mobile-1.4.3.min.js"></script>
<script type="text/javascript">
var areaIdvalue=1;
var layoutIdvalue=1;
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady()
{
loadLayot();
loadAreaButton();
loadTableData();
}
function loadTableData()
{
$('.table1').html('');
var param = "{'areaId':" + areaIdvalue + ",'layoutId':" + layoutIdvalue + "}";
$.ajax({
type: "POST",
url: "http://192.168.0.70:81/MobileService.asmx/GetTables",
data: param,
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
cache: false,
success: function (msg) {
var Tabels = msg.d;
$.each(Tabels, function(index, table) {
var tabel_data='<div class="table"';
tabel_data +=' style="top:'+ table.PointY +'px;';
tabel_data +='left:'+table.PointX+'px;"';
tabel_data +=" ' >"+table.TableName +"</div>";
$('.table1').append(tabel_data);
});
$(".table").on("tap",function(){
window.location = "AddItems.html";
});
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert('error');
alert(errorThrown);
}
});
}
function loadLayot(){
var param = "{'areaId':" + areaIdvalue + "}";
$.ajax({
type:'POST',
url :"http://192.168.0.70:81/MobileService.asmx/FetchLayout",
dataType:"json",
data: param,
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
cache: false,
success : function (msg) {
var Tabels = msg.d;
$.each(Tabels, function(index, table) {
var div_data="<option value="+table.LayoutId+">"+table.LayoutName+"</option>";
//alert(div_data);
$(div_data).appendTo('#Layout');
$('#Layout').selectmenu('refresh');
});
$('#pageOne').on("change", '#Layout', function() {
layoutIdvalue=$('#Layout').val();
loadTableData();
});
},
error : function (XMLHttpRequest, textStatus, errorThrown) {
alert('error');
alert(errorThrown);
}
});
}
function loadAreaButton(){
$.ajax({
type:'POST',
url :"http://192.168.0.70:81/MobileService.asmx/FetchArea",
dataType:"json",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
cache: false,
success : function (msg) {
var Tabels = msg.d;
$.each(Tabels, function(index, table) {
var div_data='<button class="ui-btn ui-btn-inline" value='+table.AreaId+'>'+table.AreaName+'</button>';
$(div_data).appendTo('#areadiv');
$(document).on('click', 'button', function() {
areaIdvalue=$(this).attr('value');
loadTableData();
return false;
});
});
},
error : function (XMLHttpRequest, textStatus, errorThrown) {
alert('error');
alert(errorThrown);
}
});
}
function callAnothePage()
{
//window.location = "AddItems.html";
$.mobile.changePage( "#pagetwo", { transition: "slidefade"} );
}
</script>
</head>
<body>
<div data-role="page" id="pageOne">
<div data-role="header" data-position="fixed">
<h1>Swift Retail</h1>
</div>
<div data-role="main" class="ui-content">
<div id="areadiv"></div>
<fieldset class="ui-field-contain">
<label for="Layout">Select Layout</label>
<select id="Layout" >
</select>
</fieldset>
<div class="table1" style="position: absolute; display: block; width:100%; height:100%"; ></div>
</div>
<div data-role="footer" data-position="fixed">
</div>
</div>
<div data-role="footer" data-position="fixed">
</div>
</div>
</body>
</html>