Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-7008] Android: tableViewRow - longpress event does not fire on TableViewRow

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2012-07-04T03:49:20.000+0000
Affected Version/sRelease 1.8.0.1
Fix Version/sRelease 2.1.0, Sprint 2012-12 API
ComponentsAndroid
Labelsapi, module_tableviewrow, qe-testadded
ReporterJon Barnhart
AssigneeVishal Duggal
Created2012-01-05T13:44:03.000+0000
Updated2012-10-11T18:15:51.000+0000

Description

Problem

Adding the eventListener of longpress to a TableViewRow does not fire the event.

Test Case

Make a project with the below app.js. Long press on the row and notice that the event never fires.
var win1 = Titanium.UI.createWindow({backgroundColor:'#000000'});

var row = Titanium.UI.createTableViewRow({height:'auto'});
var view = Titanium.UI.createView({backgroundColor:'red',width:'90%',height:'100%'});
row.add(view);
row.addEventListener('longpress', TableViewRowLongPress);

var table = Titanium.UI.createTableView();
table.appendRow(row);
win1.add(table);

function TableViewRowLongPress(evt)
{
  Ti.API.info('****TableViewRow longpress');
}

win1.open();

More Information

The above Test Case is not normally how we add data to a TableView. When assigning the data property of the TableView to an array you do not have access to the TableViewRow to attach a longpress listener. What would really be nice is to have the longpress event handled by the TableView itself and have the same information passed in the evt parameter as the click event (ie. row, rowData).

Comments

  1. Shawn Lipscomb 2012-01-18

    Yes, please add longpress to TableView for Android and iOS (if you want to add/fix it to TableViewRow also, go ahead...but having it on TableView is more useful).
  2. Paul Dowsett 2012-01-26

    Shawn If you require this event for TableView, then please raise a ticket. Thank you
  3. Shawn Lipscomb 2012-02-09

    Shouldn't event propagation automatically fire longpress on the row, section, and TableView itself? Appcelerator documentation says _"Events automatically propagate to parent views"_.
  4. Shawn Lipscomb 2012-03-01

    Hey Ping, will this event propagate up to the TableView when you're done fixing it?
  5. Ping Wang 2012-03-02

    Another test case:
       
       var win = Ti.UI.createWindow();
       var blueView = Ti.UI.createView({
         name: "blueView",
         backgroundColor: 'blue',
         width: 500,
         height: 500
       });
       var whiteView = Ti.UI.createView({
         name: "whiteView",
         backgroundColor: 'white',
         width: 350,
         height: 350
       });
       var redView = Ti.UI.createView({
         name: "redView",
         backgroundColor: 'red',
         width: 200,
         height: 200
       });
       var greenView = Ti.UI.createView({
         name: "greenView",
         backgroundColor: 'green',
         width: 100,
         height: 100
       });
       
       blueView.add(whiteView);
       whiteView.add(redView);
       win.add(blueView);
       win.add(greenView);
       
       blueView.addEventListener('doubletap', function(e) {
         Ti.API.info('*************Blue View doubletap: e.source = ' + e.source.name);
       });
       
       blueView.addEventListener('dblclick', function(e) {
         Ti.API.info('*************Blue View dblclick: e.source = ' + e.source.name);
       });
       
       blueView.addEventListener('singletap', function(e) {
         Ti.API.info('*************Blue View singletap: e.source = ' + e.source.name);
       });
       
       blueView.addEventListener('longpress', function(e) {
         Ti.API.info('*************Blue View longpress: e.source = ' + e.source.name);
       });
       
       blueView.addEventListener('click', function(e) {
         Ti.API.info('*************Blue View click: e.source = ' + e.source.name);
       });
       
       win.open();
       
    Testing steps: 1. Run the above code 2. Click/singletap/doubletap/doubleclick/longpress the blue/white/red area. Should see some output in the log. 3. Click/singletap/doubletap/doubleclick/longpress the green area. Should not see any output in the log.
  6. Ping Wang 2012-03-02

    Hey Shawn, events will propagate to the TableView after my fix.
  7. Shawn Lipscomb 2012-03-05

    That's good news, Ping! Here's a modification of the original testcase, specific to TableViews, to test that longpress propagates up from the TableViewRow to the TableView: {noformat} var win1 = Titanium.UI.createWindow({backgroundColor:'#000000'}); var row1 = Titanium.UI.createTableViewRow({height:'auto'}); var view1 = Titanium.UI.createView({backgroundColor:'red',width:'90%',height:'100%'}); row1.add(view1); var table1 = Titanium.UI.createTableView(); table1.appendRow(row1); win1.add(table1); table1.addEventListener('longpress', TableViewLongPress); function TableViewLongPress(evt) { Ti.API.info('****TableView recognized longpress on row # '+evt.index); } win1.open(); {noformat}
  8. Natalie Huynh 2012-03-13

    Tested with Droid 2.2.2 with 2.0.0.v20120312213243
  9. Shawn Lipscomb 2012-03-19

    After testing, I've noticed that on Android, "longclick" is the event that will be noticed (instead of "longpress") at the TableView level, and the event's properties are: index, rowData, source, and type. This works for me.
  10. Shawn Lipscomb 2012-04-03

    I don't think we're quite there yet. "longclick" will fire at the TableView level, and its event carries index, rowData, source, and type properties. "longpress" will fire at the View level, but not the TableView level. It needs to propagate up to the TableView level and have row-specifying properties on its event. It needs index, rowData, source, and type properties.
  11. Shawn Lipscomb 2012-04-17

    HD ticket: http://support.appcelerator.com/tickets/APP-843858 (for additional properties on the 'longpress' event).
  12. Vishal Duggal 2012-06-04

    Additional data for the longpress event is a new feature and not in the scope of this bug. There are already tickets (TIMOB-8795, TIMOB-8796) open for the new feature. Resolving this bug
  13. Payminder Singh 2012-06-23

    Titanium Studio: 2.1.0.201206221045 & 2.0.2 Mobile SDK: 2.1.0.v20120622174154 OS: X Lion Device: Samsung Galaxy Can't reproduce. 1. Based on updates test case (Ping Wang added a comment - 02/Mar/12 3:57 PM) unable to reproduce the bug. Longpress event does get fired.
  14. Shyam Bhadauria 2012-07-04

    Re-opening to edit label.

JSON Source