Search code examples
androidtitanium

loading screen when window opening up: Android


i am using the Titanium studio for developing android application. a user click on item a new window is being opened which fetch data from a site and populate the tableview. so this window does take time to open. mean while i am fetching the data and showing loading screen like:

anotherWind.addEventListener('open', function (e) {
      activityIndicator.show();

      setTimeout(function(){
    e.source.close();
    activityIndicator.hide();
  }, 6000);
});

the problem is at this point i'm assuming it takes 6 second to fetch and display a tableview. but in real time it may not be the case as time may vary depending upon the data

when user click a icon it should display the loading screen only for the time data is not pulated and showed in tableview.

its a kind of notification between two tasks. one when task is complted it should notify other one.
how can i resolve that ?


Solution

  • You can use a custom event listener. Example:

    Ti.App.addEventListener('tableDataLoaded', function() {
         activityIndicator.hide();
    }
    

    When your table data is loaded, you fire the event:

    Ti.App.fireEvent('tableDataLoaded');
    

    I hope this will help you :)