[TIMOB-12022] Android: TableView section number wrong on events fired
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | High |
Status | Closed |
Resolution | Invalid |
Resolution Date | 2014-02-20T15:28:12.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | Android |
Labels | n/a |
Reporter | Karl Rowley |
Assignee | Sunila |
Created | 2012-12-11T17:20:24.000+0000 |
Updated | 2017-03-28T20:54:01.000+0000 |
Description
Run the attached program.
Click on a section
Actual results: Section number is always 12
Expected results: Section number should be 1 to 12
var RED = 'Red',
GREEN = 'Green',
PURPLE = 'Purple';
var win1 = Titanium.UI.createWindow({
backgroundColor:'#fff',
layout: 'vertical'
});
var table = Ti.UI.createTableView({
});
var tableSection1 = createSectionForGroup(RED);
var tableSection2 = createSectionForGroup(GREEN);
var tableSection3 = createSectionForGroup(PURPLE);
var tableSection4 = createSectionForGroup(PURPLE);
var tableSection5 = createSectionForGroup(RED);
var tableSection6 = createSectionForGroup(GREEN);
var tableSection7 = createSectionForGroup(PURPLE);
var tableSection8 = createSectionForGroup(PURPLE);
var tableSection9 = createSectionForGroup(RED);
var tableSection10 = createSectionForGroup(GREEN);
var tableSection11 = createSectionForGroup(PURPLE);
var tableSection12 = createSectionForGroup(PURPLE);
var tableRow = Ti.UI.createTableViewRow({
title:'Row'
});
var rows = 7;
for(i=0; i<=rows; i++) {
tableSection1.add(tableRow);
}
for(i=0; i<=rows; i++) {
tableSection2.add(tableRow);
}
for(i=0; i<=rows; i++) {
tableSection3.add(tableRow);
}
for(i=0; i<=rows; i++) {
tableSection4.add(tableRow);
}
for(i=0; i<=rows; i++) {
tableSection5.add(tableRow);
}
for(i=0; i<=rows; i++) {
tableSection6.add(tableRow);
}
for(i=0; i<=rows; i++) {
tableSection7.add(tableRow);
}
for(i=0; i<=rows; i++) {
tableSection8.add(tableRow);
}
for(i=0; i<=rows; i++) {
tableSection9.add(tableRow);
}
for(i=0; i<=rows; i++) {
tableSection10.add(tableRow);
}
for(i=0; i<=rows; i++) {
tableSection11.add(tableRow);
}
for(i=0; i<=rows; i++) {
tableSection12.add(tableRow);
}
tableSection1.addEventListener( 'click', function( e ) {
alert( 'section 1 was clicked' );
});
tableSection2.addEventListener( 'click', function( e ) {
alert( 'section 2 was clicked' );
});
tableSection3.addEventListener( 'click', function( e ) {
alert( 'section 3 was clicked' );
});
tableSection4.addEventListener( 'click', function( e ) {
alert( 'section 4 was clicked' );
});
tableSection5.addEventListener( 'click', function( e ) {
alert( 'section 5 was clicked' );
});
tableSection6.addEventListener( 'click', function( e ) {
alert( 'section 6 was clicked' );
});
tableSection7.addEventListener( 'click', function( e ) {
alert( 'section 7 was clicked' );
});
tableSection8.addEventListener( 'click', function( e ) {
alert( 'section 8 was clicked' );
});
tableSection9.addEventListener( 'click', function( e ) {
alert( 'section 9 was clicked' );
});
tableSection10.addEventListener( 'click', function( e ) {
alert( 'section 10 was clicked' );
});
tableSection11.addEventListener( 'click', function( e ) {
alert( 'section 11 was clicked' );
});
tableSection12.addEventListener( 'click', function( e ) {
alert( 'section 12 was clicked' );
});
table.setData([tableSection1, tableSection2, tableSection3, tableSection4, tableSection5, tableSection6, tableSection7, tableSection8,
tableSection9, tableSection10, tableSection11, tableSection12]);
win1.add(table);
// open tab group
win1.open();
function createSectionForGroup(group) {
var headerContainerOpts, headerBottomBorderOpts, headerViewOpts;
headerViewOpts = {
color: 'white',
height: Ti.UI.SIZE,
font: { fontSize: '17sp', fontWeight: 'bold' },
left: 11,
text: group
};
if (group === RED) {
headerContainerOpts = {
backgroundGradient: {
endPoint: { x: 0, y: '100%' },
startPoint: { x: 0, y: 0 },
type: 'linear',
colors: ['#C53019', '#B32D14']
},
height: 32
};
}
if (group === GREEN) {
headerContainerOpts = {
backgroundGradient: {
endPoint: { x: 0, y: '100%' },
startPoint: { x: 0, y: 0 },
type: 'linear',
colors: ['#2B781E', '#195010']
},
height: 32
};
}
if (group === PURPLE) {
headerContainerOpts = {
backgroundGradient: {
endPoint: { x: 0, y: '100%' },
startPoint: { x: 0, y: 0 },
type: 'linear',
colors: ['#873DA6', '#612A7D']
},
height: 32
};
}
var container = Ti.UI.createView(headerContainerOpts);
container.add(Ti.UI.createLabel(headerViewOpts));
return Ti.UI.createTableViewSection({
headerView: container,
title: group
});
}
I think the issue is because the same tableRow is added to different sections, parent section for the row is updated each time with the new section and the last section sticks. When the row is clicked, since the parent is updated with the last section, it calls the handler for the last section. Try creating different tableRows
Since the same tablerow is added to all the section, tablerow get updated with the last section that was added to. Use different tablerow objects
Closing ticket as invalid.