Quantcast
Channel: Appcelerator Developer Center Q&A Tag Feed (choppy)
Viewing all articles
Browse latest Browse all 9

Slow custom tableview's. Am I doing anything wrong in my code?

$
0
0

Hi all,

I have some nice custom tableviews made up using the following code. I've only posted a portion of the code as its quite long. The general idea is that I get a list of news articles from an XML feed source, parse it in a loop and run the addthreadrow function on each article to add the data into a the row. The row is then added to a running data variable, which is then added to the tableview after all the rows are processed.

I've added snippets of the important code below int he hope that Im doing something totally wrong which accounts for the slow speed. The speed is actually not bad on the iPhone 4s, but on the iphone 4 or ipod touch its quite choppy.

Thanks for taking the time to look and if any other piece of code migth be needed to be seen, just ask.

Thanks!

function addthreadrow(row,item,datasf,x)
{
    var title = item.getElementsByTagName("title").item(0).text;
 
        var titlelabel = Ti.UI.createLabel({
            text:title,
            width:242,
            left:15,    
            top:8,
        height:20,
        color:'#333',
        font:{fontSize:14, fontFamily:'Helvetica Neue', fontWeight:'bold'},
            });
        row.add(titlelabel);
 
    var excerpt = item.getElementsByTagName("excerpt").item(0).text;
 
        var excerptlabel = Ti.UI.createLabel({
          text:excerpt,
          width:235,       
          left:25,             
          top:25,
      height:20,
      font:{fontSize:12,fontFamily:'Arial'},
      color:'#333',
      highlightedColor:'#fff'
        });
        row.add(excerptlabel);
 
 
        var date = item.getElementsByTagName("date").item(0).text;
        var datelabel = Ti.UI.createLabel({
          text:date,
          width:45,
          left:8,           
          top:32,
          height:30,
          font:{fontSize:9, fontFamily:'Arial'},
          color:'#999',
          textAlign:'center'
        });
        row.add(datelabel);             
 
        var comments = item.getElementsByTagName("commentcount").item(0).text;
        var commentslabel = Ti.UI.createLabel({
          text:comments,
          left:10,
          top:12,
          width:40,
          height:18,
          font:{fontSize:10,fontFamily:'Helvetica Neue',fontWeight:'Bold'},
          //color:'#eaeaea',
          color:'#fff',
          textAlign:'center',
          backgroundColor:'#0088ee',
          //backgroundColor:'#1455ae',
          borderRadius:5
        });
        row.add(commentslabel);
 
        var sepline = Ti.UI.createView({
                        backgroundColor:"#e6e6e6",
                        height:1,
                        width:320,
                        bottom:0
                    });     
        row.add(sepline);                   
 
}
var tableviewsf = Titanium.UI.createTableView({top:40, backgroundColor:'transparent', separatorStyle:'none'});
 
        var row = Ti.UI.createTableViewRow({
            height:65,
            className:'newslisting1',           
        backgroundColor:'#fff'          
        }); 
 
XML FEED LOOP HERE
while ... {
addthreadrow(row,item); 
datasf[x++] = row;
}
Once the loop is done, I do the following the add the compiled data into my tableview data
tableviewsf.data = datasf;

Viewing all articles
Browse latest Browse all 9

Trending Articles