如何拉动刷新?
在Titanium appcelerator中,我需要在tableview中显示内容列表。如果我拉视图,则需要更新。在iPhone中我完成但在Android中它不会工作。请帮助解决Android中的这个问题。
我的Android代码: -
tableView.addEventListener('scroll',function(e)
{
var offset = e.contentOffset.y;
if (offset < -65.0 && !pulling && !reloading)
{
var t = Ti.UI.create2DMatrix();
t = t.rotate(-180);
pulling = true;
arrow.animate({transform:t,duration:180});
statusLabel.text = "Release to refresh...";
}
else if((offset > -65.0 && offset < 0 ) && pulling && !reloading)
{
pulling = false;
var t = Ti.UI.create2DMatrix();
arrow.animate({transform:t,duration:180});
statusLabel.text = "Pull down to refresh...";
}
});
tableView.addEventListener('dragEnd', function(e)
{
if(pulling && !reloading)
{
reloading = true;
pulling = false;
arrow.hide();
actInd.show();
statusLabel.text = "Reloading...";
tableView.setContentInsets({top:60},{animated:true});
tableView.scrollToTop(-60,true);
arrow.transform=Ti.UI.create2DMatrix();
beginReloading();
}
});
答案 0 :(得分:0)
这只是厨房水槽示例中的IOS代码吗?
有几次尝试在Android上使用它,但我还没有确认它们中的任何一个按预期工作。据我所知,问题是你无法在Android中获得与在IOS中相同的偏移量。
快速Google搜索显示此链接,该链接是从官方Appcelerator论坛引用的。 https://gist.github.com/903895
答案 1 :(得分:0)
Titanium现在支持使用Titanium.UI.TableView,Titanium.UI.ListView或Titanium.UI.ScrollView对象的Android(> v6.2.0)和iOS(> 3.2.0)的刷新刷新。
查看文档:
取自文档的示例代码:
var win = Ti.UI.createWindow({
fullscreen:true
});
var counter = 0;
function genData() {
var data = [];
for (var i=1; i<=3; i++) {
data.push({properties:{title:'ROW '+(counter+i)}})
}
counter += 3;
return data;
}
var section = Ti.UI.createListSection();
section.setItems(genData());
var control = Ti.UI.createRefreshControl({
tintColor:'red'
})
var listView = Ti.UI.createListView({
sections:[section],
refreshControl:control
});
control.addEventListener('refreshstart',function(e){
Ti.API.info('refreshstart');
setTimeout(function(){
Ti.API.debug('Timeout');
section.appendItems(genData());
control.endRefreshing();
}, 2000);
})
win.add(listView);
win.open();