Skip to content

Instantly share code, notes, and snippets.

@alanleard
Last active December 24, 2015 01:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alanleard/6721869 to your computer and use it in GitHub Desktop.
Save alanleard/6721869 to your computer and use it in GitHub Desktop.
Android tableView pull to refresh and no results alert
var win = Ti.UI.currentWindow;
var alertDialog = Titanium.UI.createAlertDialog({
title: 'System Message',
buttonNames: ['OK']
});
var data = [
{title:"Refresh",color:'#000',height:50},
{title:"Row 1",color:'#000',height:50},
{title:"Row 2",color:'#000',height:50},
{title:"Row 3",color:'#000',height:50},
{title:"Row 4",color:'#000',height:50},
{title:"Row 5",color:'#000',height:50},
{title:"Row 6",color:'#000',height:50},
{title:"Row 7",color:'#000',height:50},
{title:"Row 8",color:'#000',height:50},
{title:"Row 9",color:'#000',height:50},
{title:"Row 10",color:'#000',height:50},
{title:"Row 11",color:'#000',height:50},
{title:"Row 12",color:'#000',height:50},
{title:"Row 13",color:'#000',height:50},
{title:"Row 14",color:'#000',height:50},
{title:"Row 15",color:'#000',height:50},
{title:"Row 16",color:'#000',height:50},
{title:"Row 17",color:'#000',height:50},
{title:"Row 18",color:'#000',height:50},
{title:"Load More",color:'#000',height:50}
];
var searchBar = Ti.UI.createSearchBar();
searchBar.addEventListener("change", function(e){
var count = 0;
for(var i in data){
//Non case sensitive version
//if(data[i].title.toLowerCase().indexOf(e.value.toLowerCase())!="-1"){
if(data[i].title.indexOf(e.value)!="-1"){
count++;
}
}
if(count == 0){
alert("No Results");
}
});
var tableView = Ti.UI.createTableView({
data: data,
width:Ti.UI.FILL,
height:Ti.UI.SIZE,
backgroundColor:'#FFF',
search:searchBar,
filterAttribute:"title"
});
// update the offset value whenever scroll event occurs
var offset = 0;
var visible = 0;
tableView.addEventListener('scroll', function(e) {
if (e.firstVisibleItem!=null) {
offset = e.firstVisibleItem;
visible = e.visibleItemCount
Ti.API.debug('offset: '+offset);
}
});
tableView.scrollToIndex(1);
tableView.addEventListener('scrollend', function(e) {
if (offset==0) {
Ti.API.info('REFRESH !!!!');
alertDialog.message = "REFRESH !!!!";
alertDialog.show();
tableView.scrollToIndex(1);
} else if ((offset+visible)==tableView.data[0].rows.length) {
Ti.API.info('LOAD MORE !!!!');
alertDialog.message = "LOAD MORE !!!!";
alertDialog.show();
tableView.scrollToIndex(offset-1);
}
});
win.add(tableView);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment