Titanium Community Questions & Answer Archive

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

Tableview list links without linking to new js file?

I have a tableview and it's a list of medical terms and I want to tap on one and then the window slides to the left and you view the term's definition.

Right now this is the code I have for the list

var data = [
{title: "abdomen", header:"A"},
{title: "ability"},
{title: "abolish"},
]

What I want is this:

{title : "abdomen", def: "stomach, stomach area, belly, tummy", 
header:"A"},
{title : "ability", def: "skill"},
{title : "abolish", def: "end, do away with, get rid of"},

And for the user to tap on the label and then the screen slides over and it creates a UIwindow or whatever that displays the def text.

I've seen the code in the kitchen sink app and every time you want to tap on something and slide over it seems you need a .js file for it. I don't want to create a .js file for every single definition.

Edit: I know in the kitchen sink you can have an alert box, but that's not what I'm looking for necessarily.

— asked December 6th 2010 by Stephen Flynn
  • tableview
0 Comments

1 Answer

  • Accepted Answer

    this should do the trick and get you started

    // this sets the background color of the master 
    // UIView (when there are no windows/tab groups on it)
    Titanium.UI.setBackgroundColor('#000');
    
    //
    // create base UI tab and root window
    //
    var win1 = Titanium.UI.createWindow({  
        title:'Tab 1',
        backgroundColor:'#fff'
    });
    var aTableView = Titanium.UI.createTableView( {
        data : [
               {title : "abdomen", def: "stomach, stomach area, belly, tummy", 
               header:"A"},
               {title : "ability", def: "skill"},
               {title : "abolish", def: "end, do away with, get rid of"}  
            ]
    });
    
    aTableView.addEventListener('click', function(data) {
            Ti.API.info("click event " + data.index);
            Ti.API.info("click event " + data.row);
            Ti.API.info("click event " + data.row.title);
            Ti.API.info("click event " + data.row.def);
    
            var defWindow = Titanium.UI.createWindow({  
                title: data.row.title,
                backgroundColor:'#fff',
                modal:true
            });
            var label1 = Titanium.UI.createLabel({
                color:'#999',
                text:data.row.def,
                font:{fontSize:20,fontFamily:'Helvetica Neue'},
                textAlign:'center',
                width:'auto'
            });
    
    
            var close_button = Titanium.UI.createButton({
                title:'Close'
            });
    
            close_button.addEventListener('click', function(data) {
                defWindow.close();
                defWindow = null;
                label1 = null;
            });
    
    
            defWindow.setLeftNavButton(close_button);
            defWindow.add(label1);
            defWindow.open();
    });    
    win1.add(aTableView);
    win1.open();
    
    — answered December 6th 2010 by Aaron Saunders
    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.