Is it possible using Android to have a window and/or view with a label and button under a tabelView control? I have a view with layout: 'vertical'. Then I add a tableView. That works fine. When I add a button or label under the tableView they do not appear. Any suggestions?
4 Answers
Accepted Answer
Hi Nando
I thought I would try and solve this one more time.
I have created another sample for you that you only need to specify the height of the bottom bar that contains the button and label you mentioned. You do not have to specify any other parameters and this will expand and shrink to fit the device height automatically.
This works on both Android and iOS. It only assumes you have a windows call win.
var data = [ { title: 'One' }, { title: 'Two' }, { title: 'Three' }, { title: 'Four' }, { title: 'Five' }, { title: 'Six' }, { title: 'Seven' }, { title: 'Eight' }, { title: 'Nine' }, { title: 'Ten' }, { title: 'Eleven' }, { title: 'Twelve' }, { title: 'Thirteen' }, { title: 'Fourteen' }, { title: 'Fifteen' } ]; var intLedgeHeight = 90; var viewLedgeBar = Ti.UI.createView({ backgroundColor: '#ccc', bottom: 0, height: intLedgeHeight, layout: 'vertical', width: Ti.UI.FILL }); win.add(viewLedgeBar); var btn = Ti.UI.createButton({ bottom: 0, height: 50, left: 10, right: 10, title: 'Button', top: 5, width: Ti.UI.FILL }); viewLedgeBar.add(btn); var lblFooter = Ti.UI.createLabel({ bottom: 5, color: '#000', height: Ti.UI.SIZE, left: 5, right: 5, text: 'This is under the table', textAlign: 'center', top: 5, width: Ti.UI.FILL }); viewLedgeBar.add(lblFooter); var tbl = Ti.UI.createTableView({ bottom: intLedgeHeight, data: data, //footerView: viewFooter, height: Ti.UI.FILL, top: 0, width: Ti.UI.FILL }); win.add(tbl);Let me know how it goes.
Did you give your tableview a height? Can you provide a minimal, but complete, code sample (like 40 lines of code in an app.js)?
Hi Nando
This will show you how to add a footerview that gets linked to the table and is placed after all rows you added.
var data = [ { title: 'One' }, { title: 'Two' }, { title: 'Three' } ]; var viewFooter = Ti.UI.createView({ height: Ti.UI.SIZE, layout: 'vertical', width: Ti.UI.FILL }); var btn = Ti.UI.createButton({ bottom: 5, height: Ti.UI.SIZE, left: 10, right: 10, title: 'Button', top: 5, width: Ti.UI.FILL }); viewFooter.add(btn); var lblFooter = Ti.UI.createLabel({ bottom: 5, height: Ti.UI.SIZE, left: 5, right: 5, text: 'This is under the table', top: 5, width: Ti.UI.FILL }); viewFooter.add(lblFooter); var tbl = Ti.UI.createTableView({ data: data, footerView: viewFooter, height: Ti.UI.FILL, top: 0, width: Ti.UI.FILL }); win.add(tbl);You also have
headerView that does the same but places it at the top.
The example use the layout property to control the internal position of the label and button to make things easier.
Hope this helps.
I appreciate the feedback. Jason you are spot on. The only problem is I don't have IOS at the moment so I cannot test on iPhone. However after testing on Android the button appears all the way at the bottom of the screen. Is there a way to tweak what you have to work on both iPhone/Android. Your solution is very elegant and I'd rather not use the absolute layout unless it is the only option. I suppose I could check what OS the user has and display a different view but if it's not necessary it would be sweet to use the same code on both devices.
Your Answer
Think you can help? Login to answer this question!