Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-13052] Android: TableViewRow index confused in row click

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2013-04-01T17:16:51.000+0000
Affected Version/sn/a
Fix Version/s2013 Sprint 07 API, 2013 Sprint 07, Release 2.1.5
ComponentsAndroid
Labelsqe-closed-3.3.0, qe-testadded, tableview, tableviewrow
ReporterPedro Enrique
AssigneeVishal Duggal
Created2013-03-13T19:07:38.000+0000
Updated2014-07-01T10:52:48.000+0000

Description

The Problem

Using Ti SDK 2.1.x... When clicking on a row, the event fires on a different one. This works fine in 3.0.x

The code

Use this code in app.js

function CheckBox() {
    var btn = Ti.UI.createButton({
        width : 28,
        height : 28,
        backgroundImage: 'check_grey.png',
        right: 10
    });

    var checked = false;
    
    btn.addEventListener('btn_click', function(){
       if(checked) {
           btn.backgroundImage = 'check_grey.png';
       } else {
           btn.backgroundImage = 'check_blue.png';
       }
       checked = !checked;
    });

    return btn;
}

function TableViewRow(n) {
    var row = Ti.UI.createTableViewRow({
        backgroundColor: '#ccc',
        className: 'my_row',
        height: 35
    });
    
    var checkBox = CheckBox();
    row.addEventListener('click', function(){
        checkBox.fireEvent('btn_click');
    });
    row.add(checkBox);
    
    var label = Ti.UI.createLabel({
        left: 10,
        width: 100,
        height: 30,
        text: 'Row #' + (n+1),
        color: 'black'
    });
    row.add(label);
    return row;
}

var win = Ti.UI.createWindow();
var tableData = [];
for(var i = 0; i < 100; i++) {
    tableData.push(TableViewRow(i));
}

var table = Ti.UI.createTableView({
    data: tableData
});
win.add(table);

win.open();

To Reproduce

1. Copy that code into app.js 2. Run on device (Galaxy S3 in my case) 3. Click on a row and you'll see the image on the button being changed 4. Scroll down and up 5. Click again and different row from the one clicked will fire the event.

Comments

  1. Vishal Duggal 2013-03-29

    Pull pending against 2_1_X branch https://github.com/appcelerator/titanium_mobile/pull/4055
  2. Priya Agarwal 2014-07-01

    Verified with: Appcelerator-Studio:3.3.0.201406271159 Sdk:3.3.0.v20140627202512 acs:1.0.14 alloy:1.4.0-rc3 npm:1.3.2 titanium:3.3.0-rc4 titanium-code-processor:1.1.1 xcode:5.1.1 OS:Maverick(10.9.3) Device:iPhone5c(v7.1.1),LG-P970(v4.0.4)

JSON Source