Titanium Community Questions & Answer Archive

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

Mobile: How-to show a detail view when klicked ?

Hi there!

How can i define a window/view as a detail view for an entry in my table and how do i link it to the "hasDetail" button?

Here's my code:

TableRow:

var tableRow = Titanium.UI.createTableViewRow({
     hasDetail: true
});

TableView:

var topTable = Titanium.UI.createTableView({
    style: Titanium.UI.iPhone.TableViewStyle.PLAIN,
    headerTitle: win1.contentTitle,
    data: [tableRow]
});

Would be nice to get a little "tutorial" for this!

— asked April 1st 2010 by Michael Gajda
  • button
  • detailview
  • linking
  • mobile
  • table
  • view
0 Comments

2 Answers

  • Accepted Answer

    tableview.addEventListener('click', function(e)
    {
    // event data
    var index = e.index;
    var section = e.section;
    var row = e.row;
    var rowdata = e.rowData;
    Titanium.API.info("row - row index = "+row+", row section = "+row);
    Titanium.UI.createAlertDialog({title:'Table View',message:'row ' + row + ' index ' + index + ' section ' + section + ' row data ' + rowdata}).show();
    });

    you have to add a click event to the tableview, inside you get various parameters from the row you clicked. depending on the current index you can create and open different windows. look into the kitchensink examples starting with table_view… and those starting with window…

    — answered April 1st 2010 by Christian Sigl
    permalink
    0 Comments
  • Hi Michael

    Just adopting Christian's starting point below, you can link the creation of a new window to a row's hasDetail property in the following way:

    topTable.addEventListener('click', function(e)
    {
        if(e.row.hasDetail)
        {
            // open a detail window
            var win = Ti.UI.createWindow({url:'detailWindow.js'});
    
            // provide access to this row's data
            win.rowData = e.rowData;
    
            Ti.UI.currentTab.open(win);
        }
    
        // else do nothing
    });
    

    Good luck!

    — answered April 2nd 2010 by James K
    permalink
    0 Comments
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.