Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Android data refresh. How do..?

I made and application that calls a JSON service via the xhr functionality. No problem (kinda). I have a setInterval going on my application calling the data every 10 seconds.

My question:

The data is calling every 10 seconds, BUT it looks like visually that the data is piling up on top of each other instead of replacing the last data call. More or less it looks like my font is getting bolder every 10 seconds. I have looked everywhere and it states the same way to do this but looks like the example are all the same but not doing what is happening to my data. Also most are using setInterval for timers or clocks. So… A bit of my code is below. Any help is very appreciated. I am almost done with the app. This is my only hang up.

var xhr = Titanium.Network.createHTTPClient();
        xhr.onerror = function(e)
        {
            Titanium.API.info("ERROR " + e.error);

            alert(e.error);
        };

function dataLoad(){
        xhr.onload = function(data)
        {
                   my code is here...        
                 };


        // open the client and encode our URL
        xhr.open('GET','http://myserviceurl.com/service');
        // send the data
        xhr.send();
};

//Interval Loading

setInterval(dataLoad, 10000);
— asked June 24th 2010 by Carlos Mosqueda
  • android
  • data
  • refresh
0 Comments

4 Answers

  • you are basically adding another view to the window, or parent-view instead of overwritting or replacing the (table)view with another (table)view, this is the cause of the visual effect

    var tableview;
    var win = Ti.UI.currentWindow;
    .
    .
    .
    function dataLoad(){
    xhr.onload = function(data)
    {
    if (typeof tableview.size !='undefined') { // use any property, that would exist, if the var is a Ti Tableview-Object
    win.remove(tableview);
    }

                 //code for generating tableviewrows/cell in a loop using the resultset
                 .
                 .
                 .
    
                 tableview = Ti.UI.createTableView({....});
    
                 win.add(tableview);
        };
    

    };

    .
    .
    .

    it might be enough to not remove the (table)view before generating a new one, only by having the tableview var declared outside of the xhr.onload method, but i have not testet it

    — answered June 24th 2010 by Christian Sigl
    permalink
    0 Comments
  • you are basically adding another view to the window, or parent-view instead of overwritting or replacing the (table)view with another (table)view, this is the cause of the visual effect

    var tableview;
    var win = Ti.UI.currentWindow;
    .
    .
    .
    function dataLoad(){
    xhr.onload = function(data)
    {
    if (typeof tableview.size !='undefined') { // use any property, that would exist, if the var is a Ti Tableview-Object
    win.remove(tableview);
    }

                 //code for generating tableviewrows/cell in a loop using the resultset
                 .
                 .
                 .
    
                 tableview = Ti.UI.createTableView({....});
    
                 win.add(tableview);
        };
    

    };

    .
    .
    .

    it might be enough to not remove the (table)view before generating a new one, only by having the tableview var declared outside of the xhr.onload method, but i have not testet it

    — answered June 25th 2010 by Christian Sigl
    permalink
    0 Comments
  • I think I am done. This is too frustrating. I have tried everything in Appcelerator. Using setInterval should not create or add the new data on top of the previous data. It should just update the data, not pile it up on top of the last. I am using a label to show my data. Is this my issue? Should I be using a tableview to show my data? If anything I think I am very close to be giving up on the Appcelerator. Thanks all.

    — answered June 25th 2010 by Carlos Mosqueda
    permalink
    0 Comments
  • Hey Carlos,

    In your xhr.onload function can you share part of your code that updates the data in the tableView?

    You should be able to use setData update the data used by a tableView without having to recreate the tableView each time which sounds like what might be going on.

    — answered June 25th 2010 by Dan Giulvezan
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.