I need help with a javascript refresh button. I'm having trouble linking the feed fetcher section to the refresh button section.
I think code lines 81 through 87 are the problem.

[code]

// create table view data object
var data = [];

var xhr = Ti.Network.createHTTPClient();
xhr.open("GET","http://rss.news.yahoo.com/rss/business");
xhr.onload = function()
{
try
{
var doc = this.responseXML.documentElement;
var items = doc.getElementsByTagName("item");
var x = 0;
var doctitle = doc.evaluate("//channel/title/text()").item(0).nodeValue;
for (var c=0;c<items.length;c++)
{
var item = items.item(c);
var thumbnails = item.getElementsByTagName("media:thumbnail");
var media;
if (thumbnails && thumbnails.length > 0)
{
media = thumbnails.item(0).getAttribute("url");

}
else
{
media="blue.png";
}

var title = item.getElementsByTagName("title").item(0).text;
var row = Ti.UI.createTableViewRow({height:80});
var label = Ti.UI.createLabel({
text:title,
left:72,
top:5,
bottom:5,
right:5
});
row.add(label);
var img;
if (Titanium.Platform.name == 'android')
{
// iphone moved to a single image property - android needs to do the same
img = Ti.UI.createImageView({
url:media,
left:5,
height:60,
width:60
});

}
else
{
img = Ti.UI.createImageView({
image:media,
left:5,
height:60,
width:60
});

}
row.add(img);
data[x++] = row;
row.url = item.getElementsByTagName("link").item(0).text;

}
var tableview = Titanium.UI.createTableView({data:data});
Titanium.UI.currentWindow.add(tableview);
tableview.addEventListener('click',function(e)
{
var d=Titanium.Platform.openURL(e.row.url);

});

// START REFRESH code
var refresh = Titanium.UI.createButton({
systemButton:Titanium.UI.iPhone.SystemButton.REFRESH
});
refresh.addEventListener('click', function()
{
tableview.Data([]);
setTimeout(function()
{
Data();
},1000);
});

if (Ti.Platform.name == 'iPhone OS') {
win2.rightNavButton = refresh;
} else {
refresh.top = 5;
refresh.title = "Refresh";
refresh.width = 200;
tableview.top = 60;
Titanium.UI.currentWindow.add(refresh);
}

Data();

//END REFRESH code

}
catch(E)
{
alert(E);
}


};
xhr.send();




[code]