hi developers,
i am trying to make contact list example , when i click on row then goes to second page and edit the row data [like name ,email] , but on second page i cannot get data by image you guys easily understand , i am using sqlite [install] database , 1st page is login page, 2nd page is contact list page image is bellow https://lh6.googleusercontent.com/-WncT4zZTmVE/UGFb401nsDI/AAAAAAAABAQ/MUZYqr2DPNk/s752/Screen+Shot+2012-09-25+at+12.49.04+PM.jpg
3rd page https://lh4.googleusercontent.com/-cmdcnP1TOpM/UGFcUdLi0DI/AAAAAAAABAY/G8LTyIQWZSM/s740/Screen+Shot+2012-09-25+at+12.49.39+PM.jpg
here is my code: for 2nd page
var currentWin = Ti.UI.currentWindow; // set the data from the database to the array function setArray(){ var db = Ti.Database.open('USERS'); var rows =db.execute('SELECT * FROM userdetails'); // create the array var dataArray = []; while (rows.isValidRow()) { var row = Ti.UI.createTableViewRow({ className:'forumEvent', // used to improve table performance selectedBackgroundColor:'white', //rowIndex:i, // custom property, useful for determining the row during events height:110 }); var urname= rows.fieldByName('name'); var name=rows.fieldByName('username'); var email= rows.fieldByName('email'); //var path = rows.fieldByName('path'); var imageAvatar = Ti.UI.createImageView({ image:'abc.jpg', left:0, top:1, width:75, height:100 }); row.addEventListener('click',function(e){ alert('You clicked row'+e.indexvalue); var win = Titanium.UI.createWindow({ title:'Edit', backgroundColor:'#fff', url:'edit.js', //data:e.index.urname, }).open(); }); row.add(imageAvatar); urname = Ti.UI.createLabel({ text:'Name: '+rows.fieldByName('name')+'', top:5, left:80, font:{ fontSize:20, fontWeight:'bold', fontFamily:'Trebuchet MS' }, }); row.add(urname); name = Ti.UI.createLabel({ text:'Username: '+rows.fieldByName('username')+'', top:30, left:80, font:{ fontSize:20, fontWeight:'bold', fontFamily:'Trebuchet MS' }, }); row.add(name); email = Ti.UI.createLabel({ text:'Email: '+rows.fieldByName('email')+'', top:60, left:80, font:{ fontSize:20, fontWeight:'bold', fontFamily:'Trebuchet MS' }, }); row.add(email); dataArray.push(row); rows.next(); }; // set the array to the tableView tableview.setData(dataArray); }; // create table view var tableview = Ti.UI.createTableView({ //data:tabledata }); currentWin.add(tableview); // call the setData function to attach the database results to the array setArray();3rd page:
/** * @author VThink */ var win = Titanium.UI.currentWindow; //Ti.UI.include('product.js'); var imageview = Ti.UI.createImageView({ image:'abc.jpg', top:10, width:75, height:100 }) win.add(imageview); imageview.addEventListener('click',function(e){ Titanium.Media.openPhotoGallery({ success:function(event) { Ti.API.info(event.data) var image = event.media; Titanium.API.info('image url:'+ image.nativePath); Ti.API.debug('Our type was: '+event.mediaType); if(event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO) { imageview.image = image; } }, cancel:function() { }, error:function(err) { Ti.API.error(err); }, mediaTypes:[Ti.Media.MEDIA_TYPE_PHOTO] }); }); var username1 = Ti.UI.createTextField({ text:name1, top:150, left:10, height:30, width:300, color:'blue', font:{ fontSize:20, fontWeight:'bold', fontFamily:'Trebuchet MS' }, borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED, }); win.add(username1); var name1 = Ti.UI.createTextField({ text:'', top:200, left:10, height:30, width:300, color:'blue', font:{ fontSize:20, fontWeight:'bold', fontFamily:'Trebuchet MS' }, borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED, }); win.add(name1); var email1 = Ti.UI.createTextField({ text:'', top:250, left:10, height:30, width:300, color:'blue', font:{ fontSize:20, fontWeight:'bold', fontFamily:'Trebuchet MS' }, borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED, }); win.add(email1); var save = Ti.UI.createButton({ title:' SAVE ', top:300, width:200, height:40, }); win.add(save);what can i do on third page so i can et value and after click save but it save on second page and update the list
1 Answer
Accepted Answer
you can pass the id of the object from the database and do the selection again in the final window.
you can create an object to pass through to the next window, something like this
var _data = { name : rows.fieldByName('name'), username : rows.fieldByName('username'), email : rows.fieldByName('email'), path : rows.fieldByName('path'), }; // save object with row row._data = _data; dataArray.push(row);
Your Answer
Think you can help? Login to answer this question!