I’ve almost finished my first app, which is a form.
There are two pages
MainView, contain all the fields
SettingView, contain a text field and two button – Add and Done button, Done button takes the user back to the MainView.
Users can enter a remote URL address of a file in the text field and when they press Add button the app will download the file into the ApplicationDirectory and through some coding it will prepopulate some of the fields in the MainView, at the moment this works fine on IOS when I restart the simulator and on Android when I go back and reopen the app.
I’d like to be able to update the current data without restarting or reopening the app, I’ve seen some example with application event through fire event listerner, but don’t know how to apply it to my code.
Can some one please guide/help me how to do it in my code. Thanks in advance.
I placed the Ti.App.fireEvent in the onload section of
settingView.js
c = Titanium.Network.createHTTPClient();
c.setTimeout(10000);
c.onload = function()
{
Ti.API.info('IN ONLOAD ');
var f = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory,'userlist.csv'); f.write(this.responseData); Ti.App.fireEvent('app:dataUpdat'); };
but don’t know what do to in the
MainView.js
if(Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory,'userlist.csv').exists()) {
// if file exists in applicationDataDirectory, use it
var fUserList = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory,'userlist.csv');
var csvUser = fUserList.read();
// This will parse a delimited string into an array of arrays.
function CSVToArray ( strData){
.
.
// Return the parsed data.
return( arrData );
};
var arrUserList = CSVToArray (csvUser);
var arrFullName = [];
var arrEmail = [];
var arrGrade = [];
// Loop through
for (var i = 1; i < arrUserList.length; ++i) {
.
.
}
1 Answer
Accepted Answer
Ti.App.addEventListener('app:dataUpdat', function(){ // read the file and update the UI here });
Your Answer
Think you can help? Login to answer this question!