Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-9702] Android: "TableView" doesn't counts rows well when there are table view sections present

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2012-09-10T10:13:48.000+0000
Affected Version/sRelease 2.1.0
Fix Version/sSprint 2012-15 API, Release 3.0.0, Sprint 2012-18 API
ComponentsAndroid
Labelsapi, community, module_tableview, qe-review, qe-testadded
ReporterIvan Skugor
AssigneeKarl Rowley
Created2012-06-13T06:11:46.000+0000
Updated2012-09-11T01:58:39.000+0000

Description

The problem

"TableView" component does not calculate number of rows well. It seems it counts rows from last section only. That cause issues when row is being updated or deleted by row index.

Test case

To see this issue, run this example:
(function() {
   
        var win = Ti.UI.createWindow({
	    backgroundColor: '#000',
	    navBarHidden: true
	});
	
	
	var tableView = Ti.UI.createTableView();
	
	var tableViewSection1 = Ti.UI.createTableViewSection({
		headerTitle: 'Section 1'
	});
	
	var rows = [];
	
	for (var i = 0; i < 10; ++i) {
		rows[i] = Ti.UI.createTableViewRow({ title: 'Row ' + i });
		tableViewSection1.add(rows[i]);
	}
	
	var tableViewSection2 = Ti.UI.createTableViewSection({
		headerTitle: 'Section 2'
	});
	
	rows = [];
	
	for (i = 0; i < 20; ++i) {
		rows[i] = Ti.UI.createTableViewRow({ title: 'Row ' + (i + 10) });
		tableViewSection2.add(rows[i]);
	}
	
	tableView.setData([ tableViewSection1, tableViewSection2 ]);
	
	tableView.addEventListener('click', function(e) {
		tableView.updateRow(e.index, Ti.UI.createTableViewRow({ title: 'NEW Row' }));
	});
	
	win.add(tableView);
	 
	win.open();
    
})();
Click on "Row 11" in second section. You'll see that "Row 21" is updated. Now click on "Row 23" and you should get exception that says that index is invalid.

Expected behavior

Row that is clicked should also be updated. This works fine on iOS, and does not work on Android even prior to 2.1 (I tested with 1.8.3).

Comments

  1. Ivan Skugor 2012-06-27

    IMHO, this issue should have bigger priority because there is no workaround and updating/deleting wrong row or crushing the app (if index is out of range) as the result of this issue is a big thing from usability point of view. Don't know how many developers use update/delete functionality, but it seems pretty basic thing to me.
  2. Ivan Skugor 2012-06-28

    Thanks. :)
  3. Ivan Skugor 2012-07-13

  4. Karl Rowley 2012-07-20

    Pull request is https://github.com/appcelerator/titanium_mobile/pull/2623
  5. Rima Umbrasas 2012-08-10

    Verified fixed with mobile sdk-2.2.0.v20120810080115 Titanium Studio, build: 2.1.1.201207271312 Device: Galaxy S III Android version 4.0.4
  6. Neha Chhabra 2012-09-04

    Row 0 of Section 1 does not change,instead the first row of section 2 i.e. row 10 changes on click of row 0. Verified on: Tested with Titanium Studio:2.1.2.201208301612 Tested with Titanium SDK: 2.2.0.v20120831200114
  7. Karl Rowley 2012-09-06

    It appears that a recent change here re-introduced a bug. Pull Request https://github.com/appcelerator/titanium_mobile/pull/2880
  8. Anshu Mittal 2012-09-11

    Verified with: SDK: 3.0.0.v20120910184912 STUDIO: 2.1.3.201209071738 Device: Samsung galaxy tab(v 3.2)

JSON Source