Hi, I am wanting to put a view in a view, I know this is not possible but is there a work around? currently I have a scrollable view with labels in. like so.
var win = Ti.UI.createWindow({ backgroundColor:'#D9D9D9' }); var scroll = Ti.UI.createScrollView({top:0,bottom:0,left:0,right:0,contentHeight:'auto',layout:'vertical'}); win.add(scroll); for (var i=0;i<obj.length;i++) { var date = Ti.UI.createLabel({height:Ti.UI.SIZE,left:10,right:10,top:5,bottom:20,text:obj[i].dateCreated}); scroll.add(date); var message = Ti.UI.createLabel({height:Ti.UI.SIZE,left:10,right:10,top:5,bottom:20,text:obj[i].message}); scroll.add(message); } win.open();But i want each iteration of the loop to be inside another view, I tried this:
var win = Ti.UI.createWindow({ backgroundColor:'#D9D9D9' }); var scroll = Ti.UI.createScrollView({top:0,bottom:0,left:0,right:0,contentHeight:'auto',layout:'vertical'}); win.add(scroll); for (var i=0;i<obj.length;i++) { var view = Ti.UI.createview({height:Ti.UI.SIZE, left:5, right:5,backgroundColor:'red'}) var date = Ti.UI.createLabel({height:Ti.UI.SIZE,left:10,right:10,top:5,bottom:20,text:obj[i].dateCreated}); // note that top & bottom are padding in between elements added to scrollV view.add(date); var message = Ti.UI.createLabel({height:Ti.UI.SIZE,left:10,right:10,top:5,bottom:20,text:obj[i].message}); // note that top & bottom are padding in between elements added to scrollV view.add(message); scroll.add(view); } win.open();This does not work.
any ideas?
1 Answer
Accepted Answer
Hi Michael,
you can indeed have sub-views contained in another view. No workarounds needed.
Looking at your code the first thing I noted is that you call "createview" while it should be "createView".
Is the "obj" array populated ?
Your Answer
Think you can help? Login to answer this question!