Hello guys, how can i display the values via textfield those are retriving from SQLite database in titanium android,please give one sample example for how to store data into database through textfield and how to display the retrived data through textfield
1 Answer
Titanium.UI.setBackgroundColor('#000'); var win = Titanium.UI.createWindow({ title:'My Window', backgroundColor:'#fff' }); win.open(); var db=Ti.Database.open('film'); var rs =false; db.execute('CREATE TABLE IF NOT EXISTS FILM (ID INTEGER, NOME TEXT)'); rs = db.execute('select count(1) `total` from FILM'); var total = rs.fieldByName('total'); //don't need to do rs.next() since this call always returns one row even if the table is empty Ti.API.log(total); if(total == 0){ //This if statement prevents the data below from being reloaded multiple times. You can also create and install a database instead which is more efficient. db.execute('INSERT INTO FILM (ID, NOME ) VALUES(?,?)',1,'Il signore degli anelli'); db.execute('INSERT INTO FILM (ID, NOME ) VALUES(?,?)',2,'Scarface'); db.execute('INSERT INTO FILM (ID, NOME ) VALUES(?,?)',3,'Harry Potter'); } rs.close(); //add on a tableview to put rows into for the output of the database //get the film data rs = db.execute('select ID,NOME from FILM'); //process the results into the tableview var row=false; var top_position= 10; //setting for text Field while(rs.isValidRow()){ var textField= Ti.UI.createTextField({ value: rs.fieldByName('ID')+' - '+rs.fieldByName('NOME'), height: 40, width: Ti.UI.SIZE, top: top_position, color : '#000', borderStyle : Titanium.UI.INPUT_BORDERSTYLE_ROUNDED, left: 10 }) win.add(textField); top_position= top_position+50; //set to for next textField rs.next();//must have this to make the result set progress to the next row. }
Your Answer
Think you can help? Login to answer this question!