I have a button event listener which, when fired, makes a call to a function (doSync()) which is defined in my app.js as an Include (the function is a frequently used function).
Upon return from doSync(), I need to update a label in the calling script. The doSync() function works fine...no problems with it.
I have defined a custom event listener ("updateInboxLabel"), which I attempt to fire after the call to doSync(). The custom listener is defined in the button click listener in which the function call is made.
However, the custom event listener is fired before the function call, and not after.
secondRowFirstIcon.addEventListener('click', function() { //Function call that, upon return, I want to update the //firstRowFirstLabel.text field (defined elsewhere). // doSync() is defined in a separate file doSync(); //Custom event listener Ti.App.addEventListener('updateInboxLabel', function(e){ numOfRows = getNumberOfAssignments(); var InboxLabel = "Inbox (" + getNumberOfAssignments() + ")"; Ti.API.info("InboxLabel: " + InboxLabel); firstRowFirstLabel.text = "Inbox ("+getNumberOfAssignments()+")"; }); var numOfRows = 0; numOfRows = getNumberOfAssignments(); var InboxLabel = "Inbox (" + getNumberOfAssignments() + ")"; Ti.API.info("InboxLabel: " + InboxLabel); firstRowFirstLabel.text = "Inbox (" + getNumberOfAssignments()+")"; Ti.App.fireEvent('updateInboxLabel'); database.close(); }); //This function defined elsewhere in the same script. Simply returns a value var getNumberOfAssignments = function() { DB = require('/databases/Database'); var database = new DB(); database.install(); var rowCountRs = database.execute('SELECT * FROM MTP_Assignments_ODA_M WHERE isPreviousAssignment = 0 AND assignStatus != "SUBMITTED"', "query"); var numOfRows = rowCountRs.rowCount; //Ti.API.info("numOfRows after success : "+ numOfRows); database.close(); return numOfRows; };
What I need to have happen is, after the call to doSync() is made, call the getNumberOfAssignments function and update the firstRowFirstLabel text.
Thanks.