hi guys..here i have a Tableview with two ROWS one with the name John and another with Max....but when i click max it does the same as john....they both come up with the scrollable view...i want have john open the scrollable view and i want Max to open a window...how do i implement that...i need example and john there i will create more row with different contents...thanks group!
var win = Ti.UI.currentWindow; var tv = Ti.UI.createTableView(); var names = [{name: 'Max'}, {name: 'John'}]; var arrRows = []; for(var idx in names) { var obj = names[idx]; var tvr = Ti.UI.createTableViewRow({title: obj.name}); arrRows.push(tvr); } tv.data=arrRows; tv.addEventListener('click', function(){ var newwin = Ti.UI.createWindow({backgroundColor:'white'}); var backBtn = Ti.UI.createButton({top:0, left:0, title:'Back'}); backBtn.addEventListener('click', function(){ newwin.close() }); var view1 = Ti.UI.createView({ backgroundImage:'01.jpg'}); var view2 = Ti.UI.createView({ backgroundImage:'41.jpg' }); var view3 = Ti.UI.createView({ backgroundImage:'02.jpg' }); var view4 = Ti.UI.createView({ backgroundImage:'05.jpg' }); var view5 = Ti.UI.createView({ backgroundImage:'07.jpg' }); var view6 = Ti.UI.createView({ backgroundImage:'09.jpg' }); var view7 = Ti.UI.createView({ backgroundImage:'10.jpg' }); var scrollableView = Ti.UI.createScrollableView({ views:[view1,view2,view3,view4,view5,view6,view7], showPagingControl:true }); newwin.add(scrollableView); newwin.add(backBtn); newwin.open(); }); win.add(tv); win.open();
6 Answers
You just have no idea of Basics, this is Not a Titanium issue, even Not Javascript. You'll get over and over again issues.
for(var idx in names) { var obj = names[idx]; var tvr = Ti.UI.createTableViewRow({title: obj.name}); . tvr.addEventListener('click', function(e) { . ... . }); arrRows.push(tvr); }
i want have john open the scrollable view and i want Max to open a window.
tv.addEventListener('click', function(e){ if (e.rowData.title == 'John'){ // Do something with John }else if (e.rowData.title == 'Max'){ //Do domething with Max } });or
tv.addEventListener('click', function(e){ if (e.index == 0){ // Do something with John }else if (e.index == 1){ //Do domething with Max } });something like that?
attach the event listener to the table rows instead of the table view.
the best way imo is to add an eventListener to the table and then, in that event listener, check which row was clicked. and do actions for each one..
example:
tv.addEventListener('click',function(e){ if(e.row.title == "Max"){ //do something.. } });
You wheb you have multiple rows...for example one row is called map...when someone clicks map it show a location....and one saying pictures when someone click it show scrollable view...i dont if the method you showing me does that...
I'm trying to add the row max to the event listener and i get a error...cant find variable Max..any ideas???
var win = Ti.UI.currentWindow; var tv = Ti.UI.createTableView(); var names = [{name: 'Max'}, {name: 'John'}]; var arrRows = []; for(var idx in names) { var obj = names[idx]; var tvr = Ti.UI.createTableViewRow({title: obj.name}); arrRows.push(tvr); } tv.data=arrRows; Max.addEventListener('click', function(){ var newwin = Ti.UI.createWindow({backgroundColor:'white'}); var backBtn = Ti.UI.createButton({top:0, left:0, title:'Back'}); backBtn.addEventListener('click', function(){ newwin.close() }); var view1 = Ti.UI.createView({ backgroundImage:'01.jpg'}); var view2 = Ti.UI.createView({ backgroundImage:'41.jpg' }); var view3 = Ti.UI.createView({ backgroundImage:'02.jpg' }); var view4 = Ti.UI.createView({ backgroundImage:'05.jpg' }); var view5 = Ti.UI.createView({ backgroundImage:'07.jpg' }); var view6 = Ti.UI.createView({ backgroundImage:'09.jpg' }); var view7 = Ti.UI.createView({ backgroundImage:'10.jpg' }); var scrollableView = Ti.UI.createScrollableView({ views:[view1,view2,view3,view4,view5,view6,view7], showPagingControl:true }); newwin.add(scrollableView); newwin.add(backBtn); newwin.open(); }); win.add(tv); win.open();
Your Answer
Think you can help? Login to answer this question!