1

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?

MysticMagicϡ
  • 28,593
  • 16
  • 73
  • 124
suresh gopal
  • 3,138
  • 6
  • 27
  • 58

3 Answers3

1

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.

Community
  • 1
  • 1
Kamleshwar
  • 2,967
  • 1
  • 25
  • 27
1

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.

suresh gopal
  • 3,138
  • 6
  • 27
  • 58
-1

Change the content height to what you want table height look

j0k
  • 22,600
  • 28
  • 79
  • 90
Omarj
  • 1,151
  • 2
  • 16
  • 43