Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

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.

— asked August 26th 2010 by Daniel Kareski
  • android
  • setfooter
  • setheader
  • tableview
0 Comments

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.

    — answered August 26th 2010 by Richard Venneman
    permalink
    1 Comment
    • This example does NOT run in the android emulator and, when trying to run the Kitchen Sink app in the android emulator to see if that app also crashes, I find that Kitchen Sink won't even run in the android emulator!!

      What are you guys doing? I'm running Titanium Studio on Mac OSX 10.6.8 with the android 2.2 SDK.

      If I can only create this type of tableview in an iPhone app and can't even create a simple tableview on android using Titanium.UI.createTableView({data:data}) - yes, also crashes - then I'd be a lot happier going back to native dev.

      The amount I time I've had to invest in what is a very simple App with Appcelerator Titanium is ridiculous when put in this context. Objective-C would have been much quicker given that my app won't run on android anyway!

      — commented August 23rd 2011 by Robert Turrall
  • 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?

    — answered August 26th 2010 by Daniel Kareski
    permalink
    1 Comment
    • Are you by any chance, in the last example, adding the TableView to the window before adding the headerView to it? That might explain the problem. Otherwise, I wouldn't know.

      — commented August 26th 2010 by Richard Venneman
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.