| GitHub Issue | n/a |
| Type | New Feature |
| Priority | Medium |
| Status | Closed |
| Resolution | Fixed |
| Resolution Date | 2014-04-17T21:29:24.000+0000 |
| Affected Version/s | Release 3.1.1, Release 3.1.2, Release 3.1.3 |
| Fix Version/s | 2014 Sprint 08, 2014 Sprint 08 SDK, Release 3.3.0 |
| Components | Android |
| Labels | listview, module_listview, qe-testadded, scrollToItem, supportTeam, triage |
| Reporter | Marco Cota |
| Assignee | Vishal Duggal |
| Created | 2013-12-16T14:24:45.000+0000 |
| Updated | 2014-04-22T21:23:30.000+0000 |
Request
In the Android listView allow user to disable animation on the scrollToItem method or set selection to a specific Section and row.
Current Behavior
The listView element is able to disable animation on scrollToItem and set selection only on iOS.
Sample Code
$.listView.scrollToItem(10, 1, {
animated: false
});
also, controlling the speed of the animation is a nice, or making it adaptive to the distance it needs to pass when it scrolls from row A to row B... slower animation when we need to move 5, 10, 20 rows, and much faster when we need to move 200,300 rows..
Test Case
var win = Ti.UI.createWindow({ backgroundColor:'white', exitOnClose:true, title:'ScrollToItem', layout:'vertical' }); var container = Ti.UI.createView({height:Ti.UI.SIZE}); win.add(container); var b1 = Ti.UI.createButton({ left:'2%', top:0, backgroundColor:'black', color:'white', title:'animated=true', width:'45%' }); var b2 = Ti.UI.createButton({ right:'2%', top:0, backgroundColor:'black', color:'white', title:'animated=false', width:'45%' }); container.add(b1); container.add(b2); var label = Ti.UI.createLabel({color:'black',height:'64dp',font:{fontSize:'14dp'}}); win.add(label); function genSection(section) { var data = []; for(i=0;i<25;i++) { data.push({properties: { title: 'SectionIndex '+section+' ItemIndex '+i}}); } var section = Ti.UI.createListSection({items:data,headerTitle:'Section '+section}); return section; } var sections = []; for(j=0;j<25;j++) { sections.push(genSection(j)); } var listView = Ti.UI.createListView({ sections:sections }); win.add(listView); win.open(); function scrollToRandom(animated) { var sIndex = Math.floor(Math.random()*31)%25; var iIndex = Math.floor(Math.random()*83)%25; label.text = 'listView.scrollToItem('+sIndex+','+iIndex+',{animated:'+animated+'})'; listView.scrollToItem(sIndex,iIndex,{animated:animated}); } b1.addEventListener('click',function(){ scrollToRandom(true); }); b2.addEventListener('click',function(){ scrollToRandom(false); });Pull pending against master https://github.com/appcelerator/titanium_mobile/pull/5620