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

Android: 'longpress' on tableView with headerView returns incorrect index and might lead to a crash

    Details

      Description

      Problem description

      If the tableview has a header, e.index returns the incorrect index for the 'longpress' event.

      If the first row is long-pressed, then e.index == 1 instead of 0. 'click' returns the correct index. If the last row is long-pressed, the SDK crashes with an IndexOutOfBoundsException. If the TableView is created without a headerView, the index values are correct.

      Only reproducible on TiSDK 3.0 as with a previous version e.index is undefined.
      Works fine on iOS.

      Steps to reproduce

      var _self = Ti.UI.createWindow({
      	backgroundColor : '#fff',
      	height : Ti.UI.FILL,
      	width : Ti.UI.FILL
      });
      var title = "TableView Bug";
      var win = Ti.UI.createView({});
      _self.add(win);
       
      var table = Ti.UI.createTableView({
      	headerTitle : title
      });
      var headerView = Ti.UI.createView({
      	backgroundColor : '#444'
      });
      var titleLabel = Ti.UI.createLabel({
      	width : _self.width,
      	textAlign : 'center',
      	color : '#eee'
      });
      headerView.add(titleLabel);
      titleLabel.text = "Title text";
      table.setHeaderView(headerView);
       
      var data = [];
      data.push(Ti.UI.createTableViewRow({
      	title : "Row 0"
      }));
      data.push(Ti.UI.createTableViewRow({
      	title : "Row 1"
      }));
      data.push(Ti.UI.createTableViewRow({
      	title : "Row 2"
      }));
      data.push(Ti.UI.createTableViewRow({
      	title : "Row 3"
      }));
      table.setData(data);
       
      win.add(table);
       
      var label = Ti.UI.createLabel({
      	height : '40dp',
      	bottom : 0,
      	text : "Label"
      });
      win.add(label);
       
      table.addEventListener('click', function(e) {
      	Ti.API.info("#### table - row " + e.index + " clicked")
      });
      table.addEventListener('longpress', function(e) {
      	Ti.API.info("#### table - row " + e.index + " longpressed")
      });
       
      _self.open();
      
      

      Pressing and long-pressing on the rows shows the index being returned.
      Long pressing the last row causes the crash:

      ==
      E/AndroidRuntime( 8867): java.lang.IndexOutOfBoundsException: Invalid index 5, size is 5
      E/AndroidRuntime( 8867): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251)
      E/AndroidRuntime( 8867): at java.util.ArrayList.get(ArrayList.java:304)
      E/AndroidRuntime( 8867): at ti.modules.titanium.ui.widget.tableview.TiTableView.getItemAtPosition(TiTableView.java:411)
      E/AndroidRuntime( 8867): at ti.modules.titanium.ui.TableViewProxy.fireEvent(TableViewProxy.java:149)
      E/AndroidRuntime( 8867): at org.appcelerator.titanium.view.TiUIView$3.onLongPress(TiUIView.java:1156)
      E/AndroidRuntime( 8867): at android.view.GestureDetector.dispatchLongPress(GestureDetector.java:1451)
      E/AndroidRuntime( 8867): at android.view.GestureDetector.access$200(GestureDetector.java:50)
      E/AndroidRuntime( 8867): at android.view.GestureDetector$GestureHandler.handleMessage(GestureDetector.java:319)
      E/AndroidRuntime( 8867): at android.os.Handler.dispatchMessage(Handler.java:99)
      E/AndroidRuntime( 8867): at android.os.Looper.loop(Looper.java:137)
      E/AndroidRuntime( 8867): at android.app.ActivityThread.main(ActivityThread.java:4898)
      E/AndroidRuntime( 8867): at java.lang.reflect.Method.invokeNative(Native Method)
      E/AndroidRuntime( 8867): at java.lang.reflect.Method.invoke(Method.java:511)
      E/AndroidRuntime( 8867): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
      E/AndroidRuntime( 8867): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
      E/AndroidRuntime( 8867): at dalvik.system.NativeStart.main(Native Method)

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                sunila Sunila
                Reporter:
                fcasali Federico Casali
                Reviewer:
                Allen Yeung
              • Watchers:
                8 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Git Source Code