How can i display an image like a throbber while the tableview is loading.
I have an rss feed that loads into a tableview. Because it has to pull the information from an .xml source on the internet it can take a second. So it looks like the app is frozen. I want to display a throbber so that the user will understand that the data is being loaded.
4 Answers
Accepted Answer
To expound on what Aaron suggested, you would want to show the throbber prior to the xhr.send() method, then hide it during the xhr.onload() or xhr.onerror() methods. An example of using an activity indicator is in this kitchen sink example.
have you looked into Titanium.UI.ProgressBar or Titanium.UI.ActivityIndicator
Could you give me an example. My code is:
// create table view data object var data = []; var xhr = Ti.Network.createHTTPClient(); xhr.open("GET","http://tweakers.net/feeds/nieuws.xml"); 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 title = item.getElementsByTagName("title").item(0).text; var row = Ti.UI.createTableViewRow({height:80}); var label = Ti.UI.createLabel({ text:title, left:5, top:5, bottom:5, right:5, color:'#FFF' }); row.add(label); 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 w = Ti.UI.createWindow({title:doctitle}); var wb = Ti.UI.createWebView({url:e.row.url}); w.add(wb); var b = Titanium.UI.createButton({ title:'Close', style:Titanium.UI.iPhone.SystemButtonStyle.PLAIN }); w.setLeftNavButton(b); b.addEventListener('click',function() { w.close(); }); w.open({modal:true}); }); } catch(E) { alert(E); } }; xhr.send();
Could you give me an example. My code is:
// create table view data object var data = []; var xhr = Ti.Network.createHTTPClient(); xhr.open("GET","http://tweakers.net/feeds/nieuws.xml"); 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 title = item.getElementsByTagName("title").item(0).text; var row = Ti.UI.createTableViewRow({height:80}); var label = Ti.UI.createLabel({ text:title, left:5, top:5, bottom:5, right:5, color:'#FFF' }); row.add(label); 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 w = Ti.UI.createWindow({title:doctitle}); var wb = Ti.UI.createWebView({url:e.row.url}); w.add(wb); var b = Titanium.UI.createButton({ title:'Close', style:Titanium.UI.iPhone.SystemButtonStyle.PLAIN }); w.setLeftNavButton(b); b.addEventListener('click',function() { w.close(); }); w.open({modal:true}); }); } catch(E) { alert(E); } }; xhr.send();
Your Answer
Think you can help? Login to answer this question!