Skip to content

Instantly share code, notes, and snippets.

@stevenwadejr
Forked from jhaynie/app.js
Created May 29, 2012 14:10
Show Gist options
  • Save stevenwadejr/2828658 to your computer and use it in GitHub Desktop.
Save stevenwadejr/2828658 to your computer and use it in GitHub Desktop.
/**
* Simple demo for adding swipe detection on a table view row. Since the row is simply a container
* of views, you'll want to generally create a hidden view the size of the row and add your swipe listener
* to this view for detection. We need to improve Titanium so you don't have to do this in the future...
*/
var win = Ti.UI.createWindow();
var data = [];
for (var c=0;c<10;c++)
{
var row = Ti.UI.createTableViewRow({height:80});
/* create a view that's 100% of the size of the row that will
capture your swipe events. i've made it red just to show the
boundaries but you'd want it to be transparent most likely */
var swipeview = Ti.UI.createView({
width:'100%',
height:80,
zIndex:100,
backgroundColor:'red',
opacity:0.1,
row:c+1
});
var label = Ti.UI.createLabel({
width:320,
height:25,
text:"Hello from row "+(c+1),
touchEnabled:false /* turn off any touch detection for this element */
});
swipeview.addEventListener('swipe',function(e)
{
alert('swipe '+e.direction+' on row '+e.source.row);
})
row.add(label);
row.add(swipeview);
data[c] = row;
}
var tv = Ti.UI.createTableView({data:data});
win.add(tv);
win.open();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment