Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-13052

Android: TableViewRow index confused in row click

    Details

      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.

        Attachments

          Activity

            People

            • Assignee:
              vduggal Vishal Duggal (Inactive)
              Reporter:
              penrique Pedro Enrique (Inactive)
              Reviewer:
              Allen Yeung
            • Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Backbone Issue Sync

                • Titanium SDK/CLI <> Titanium Mobile
                  Synced with:
                  TIMOB-15885
                  Sync status:
                  ERROR
                  Last received:
                  Last sent:

                  Git Source Code