Search code examples
titaniumtitanium-mobiletitanium-modules

Titanium android data reflection in table view


Google APIs Android 2.3.1 , data changes in the database tables not reflecting in tableview screens, but if we restart the app, will show changes and also, if we load app.js will show recent changes.

Can anyone help me to fix this??

fireEvent("db_update") 

&
addEventListener('db_update', function() { what should be here to update table data })


Solution

  • I found the solution,

    Ti.App.addEventListener('updatedb', updateData);
    

    here 'updateData' is the function which gets the data for tableview from the databae. At the bottom of 'updateData' function, set data for table view

    i.e)   tableview.setData(data);
    

    and then, your insert, update or delete function should trigger 'updatedb' function

    i.e)

    function deleteData(recId)  {
        var db = Ti.Database.open(DBNAME);
            db.execute(" DELETE FROM tblName WHERE id IN("+ recId+") ");
            db.close();
    
        Ti.App.fireEvent('dataupdated');
    }
    

    now, after calling deleteData function, your tableview data will show w/o deleted record.