suresh gopal
suresh gopal

Reputation: 3156

How to set row Height on a tableView that is dynamically populated? (Titanium Studio)

I am new to Titanium Studio. Need to set row height dynamically but, I unable to set dynamic height in each row. Below is my code:

textArray contains 10 text paragraphs. each paragraph have different height.

var myTable = Ti.UI.createTableView({height:360, width: 306, top: 58, backgroundColor: '#FFFFFF',borderColor: '#C8C8C8',borderWidth:2, zIndex: -1});
var myArray = [];

for(int i = 0; i < 10; i++)
{

    var row = Ti.UI.createTableViewRow({contentHeight: 'auto', width: 320,top:0});

    var my = Ti.UI.createView({ top:10,width:300,height:'auto' });

    var myText = Ti.UI.createlLabel({text:textArray[i],width:50,height:'auto',left:10,top:5,borderRadius:4});

    my.add(myText);

    row.add(my);
    myArray.push(row);

}

How can i set row height dynamically.

Can any one help?

Upvotes: 1

Views: 3976

Answers (3)

suresh gopal
suresh gopal

Reputation: 3156

I got the solution:

specify your table rowHeight as auto.

var myTable = Ti.UI.createTableView({height:400,rowHeight: 'auto', width: 312, top: 10,left:4, backgroundColor: '#FFFFFF',borderColor: '#C8C8C8',borderWidth:2, zIndex: -1});
var myArray=[];   

for(int i = 0; i < 10; i++)
{
    //create row in table.
    var row = Ti.UI.createTableViewRow({height: 'auto', width: 310,top:10, selectionStyle : Titanium.UI.iPhone.TableViewCellSelectionStyle.NONE});

    //textArray contains 10 elements. i am using this in each loop..
    var myText = Ti.UI.createlLabel({text:textArray[i],width:50,height:50,left:10,top:5,borderRadius:4});

    //add like this what ever you want...
    row.add(myText);

    myArray.push(row);

}

//store in table
myTable.data = myArray;

//disply table.
win.add(myTable);

If height:'auto' property is not working then use Ti.UI.SIZE

I hope.. someone will use it.

Upvotes: 1

Omarj
Omarj

Reputation: 1159

Change the content height to what you want table height look

Upvotes: -1

Kamleshwar
Kamleshwar

Reputation: 2997

As per understanding you need to show cell height as per text

Here are some good example

  1. Similar post on Stackoverflow

  2. Example given on some blog

Hope this will solve you problem.

Upvotes: 1

Related Questions