views in view

You must Login before you can answer or comment on any questions.

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 ?

— answered 7 months ago by Marco Del Tongo
answer permalink
2 Comments
  • oops, well i feel foolish this works fine now, Thanks.

    — commented 7 months ago by Michael Sagar

  • Ah ah ah, don't worry, often only eyes with a fresh view of code can spot these kind of things...

    P.S.: Please mark this question as closed with the answer below if you want, so that it won't show in unanswered list.

    Have fun and code strong !

    — commented 7 months ago by Marco Del Tongo

Your Answer

Think you can help? Login to answer this question!