Skip to content

Instantly share code, notes, and snippets.

@adampax
Created September 25, 2011 20:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adampax/1241077 to your computer and use it in GitHub Desktop.
Save adampax/1241077 to your computer and use it in GitHub Desktop.
Use Titanium Picker to Update Scrollable View
var win = Titanium.UI.createWindow({
title : 'test'
});
var view1 = Ti.UI.createView({
backgroundColor:'red'
});
var l1 = Ti.UI.createLabel({
text:'View 1',
color:'#fff',
width:'auto',
height:'auto'
});
view1.add(l1);
var view2 = Ti.UI.createView({
backgroundColor:'blue'
});
var l2 = Ti.UI.createLabel({
text:'View 2',
color:'#fff',
width:'auto',
height:'auto'
});
view2.add(l2);
var view3 = Ti.UI.createView({
backgroundColor:'green'
});
var l3 = Ti.UI.createLabel({
text:'View 3',
color:'#fff',
width:'auto',
height:'auto'
});
view3.add(l3);
var view4 = Ti.UI.createView({
backgroundColor:'black'
});
var l4 = Ti.UI.createLabel({
text:'View 4',
color:'#fff',
width:'auto',
height:'auto'
});
view4.add(l4);
var scrollView = Titanium.UI.createScrollableView({
views:[view1,view2,view3,view4],
showPagingControl:true,
pagingControlHeight:30,
maxZoomScale:2.0,
currentPage:0,
height:180,
top:0
});
win.add(scrollView);
//picker stuff
var picker = Ti.UI.createPicker({
bottom:0
});
var data = [];
data[0]=Ti.UI.createPickerRow({title:'View 1',custom_item:0});
data[1]=Ti.UI.createPickerRow({title:'View 2',custom_item:1});
data[2]=Ti.UI.createPickerRow({title:'View 3',custom_item:2});
data[3]=Ti.UI.createPickerRow({title:'View 4',custom_item:3});
// turn on the selection indicator (off by default)
picker.selectionIndicator = true;
picker.add(data);
win.add(picker);
picker.addEventListener('change',function(e)
{
scrollView.currentPage = e.row.custom_item;
});
win.open();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment