Problem with tableView's setHeader and setFooter in Android
Hi to all,
I have a problem with setting the header and the footer in a tableView. When I set the property when creating the table object it keeps crashing with strange NullPointer exception. Can anyone show me the simplest WORKING example on Android how to set header and footer in using a view in a tableView or maybe some workaround.
Your help is much appreciated.
2 Answers
-
From the Kitchen Sink there's an example where the table properties are being set from an object like this:
// create table view var tableViewOptions = { data:data, style:Titanium.UI.iPhone.TableViewStyle.GROUPED, headerTitle:'TableView examples and test cases', footerTitle:"Wow. That was cool!", backgroundColor:'transparent', rowBackgroundColor:'white' }; var tableview = Titanium.UI.createTableView(tableViewOptions);
Try this, it might work.
-
Thanks for the reply.
The problem that I encountered was setting a whole custom made view(with labels and images) as a header or footer. I am sorry if I was not clear enough. The code above works fine.
Later I realized that this code works and it shows the header just fine:
var headerView = Ti.UI.createView({ height: 'auto', width: Ti.Platform.displayCaps.platformWidth - 20, left: 10, top: 10 }); headerView.add(Titanium.UI.createLabel({ color:'#999', text:'header', font:{fontSize:20,fontFamily:'Helvetica Neue'}, textAlign:'center', width:'auto' })); var ob = Titanium.UI.createTableView({ backgroundColor: 'transparent', top: 0, left: 0, bottom: 0, right: 0, rowHeight: 'auto', separatorColor: 'black', headerView: headerView });
and this code simply does not show the header at all:
var headerView = Ti.UI.createView({ height: 'auto', width: Ti.Platform.displayCaps.platformWidth - 20, left: 10, top: 10 }); headerView.add(Titanium.UI.createLabel({ color:'#999', text:'header', font:{fontSize:20,fontFamily:'Helvetica Neue'}, textAlign:'center', width:'auto' })); var ob = Titanium.UI.createTableView({ backgroundColor: 'transparent', top: 0, left: 0, bottom: 0, right: 0, rowHeight: 'auto', separatorColor: 'black', }); ob.headerView = headerView;
Any thoughts about that?