Quantcast
Viewing all articles
Browse latest Browse all 28

Puting switches in a tableview

Hi! I am trying to create a search app where the user has a bunch of switch type controls where he makes the selections he wants and then pushes a button to do the search. I am trying to create the search view, and trying to put the switches in a Tableview with three switches in each row. Since the search options might change, I am using an array (usosGen) with the names of the switches so that I can later on modify that array depending on the situation.

My problem is that when I run the code, eventhough the variable 'target' displays with the correct name of the switch I want to add to the row, i get an error message saying: "Invalid value: expected type Object." I will appreciate any insight into what i am doing or any input on how to do this easier. Thanks in advance for your assistance.

HERE IS MY CODE FOR THIS:

var view = Ti.UI.createScrollView({

contentWidth: 'auto',

contentHeight: 'auto',

showVerticalScrollIndicator: true,

showHorizontalScrollIndicator: false,

backgroundColor: 'black'

});

// Create all the swiches.

var TiestosSwitch = Ti.UI.createSwitch({

style: Ti.UI.Android.SWITCH_STYLE_CHECKBOX,

textAlign:Ti.UI.TEXT_ALIGNMENT_CENTER,

title:'Tiestos',

font: 'Helvetica',

font: { fontSize:10 },

color:'White',

value:false,

top:'385dp',

width: 100// necessary for textAlign to be effective

});

var JardinerasSwitch = Ti.UI.createSwitch({

style: Ti.UI.Android.SWITCH_STYLE_CHECKBOX,

textAlign:Ti.UI.TEXT_ALIGNMENT_CENTER,

title:'Jardineras',

font: 'Helvetica',

font: { fontSize:8 },

color:'White',

value:false,

top:'420dp',

width: 100 // necessary for textAlign to be effective

});

var TopiariosSwitch = Ti.UI.createSwitch({

style: Ti.UI.Android.SWITCH_STYLE_CHECKBOX,

textAlign:Ti.UI.TEXT_ALIGNMENT_CENTER,

title:'Topiarios',

font: 'Helvetica',

font: { fontSize:8 },

color:'White',

value:false,

top:'455dp',

width: 100 // necessary for textAlign to be effective

});

var TrellisSwitch = Ti.UI.createSwitch({

style: Ti.UI.Android.SWITCH_STYLE_CHECKBOX,

textAlign:Ti.UI.TEXT_ALIGNMENT_CENTER,

title:'Trellis',

font: 'Helvetica',

font: { fontSize:8 },

color:'White',

value:false,

top:'490dp',

width: 100 // necessary for textAlign to be effective

});

var TotemSwitch = Ti.UI.createSwitch({

style: Ti.UI.Android.SWITCH_STYLE_CHECKBOX,

textAlign:Ti.UI.TEXT_ALIGNMENT_CENTER,

title:'Totem',

font: 'Helvetica',

font: { fontSize:8 },

color:'White',

value:false,

width: 100 // necessary for textAlign to be effective

});

var TroncosSwitch = Ti.UI.createSwitch({

style: Ti.UI.Android.SWITCH_STYLE_CHECKBOX,

textAlign:Ti.UI.TEXT_ALIGNMENT_CENTER,

title:'Troncos',

font: 'Helvetica',

font: { fontSize:10 },

color:'White',

value:false,

width: 100 // necessary for textAlign to be effective

});

var InteriorSwitch = Ti.UI.createSwitch({

style: Ti.UI.Android.SWITCH_STYLE_CHECKBOX,

textAlign:Ti.UI.TEXT_ALIGNMENT_CENTER,

title:'Interior',

font: 'Helvetica',

font: { fontSize:10 },

color:'White',

value:false,

width: 100 // necessary for textAlign to be effective

});

var CanastasSwitch = Ti.UI.createSwitch({

style: Ti.UI.Android.SWITCH_STYLE_CHECKBOX,

textAlign:Ti.UI.TEXT_ALIGNMENT_CENTER,

title:'Canastas',

font: 'Helvetica',

font: { fontSize:10 },

color:'White',

value:false,

width: 100 // necessary for textAlign to be effective

});

var ParedesVerdesSwitch = Ti.UI.createSwitch({

style: Ti.UI.Android.SWITCH_STYLE_CHECKBOX,

textAlign:Ti.UI.TEXT_ALIGNMENT_CENTER,

title:'Paredes verdes',

font: 'Helvetica',

font: { fontSize:10 },

color:'White',

value:false,

width: 100 // necessary for textAlign to be effective

});

var PrivacidadSwitch = Ti.UI.createSwitch({

style: Ti.UI.Android.SWITCH_STYLE_CHECKBOX,

textAlign:Ti.UI.TEXT_ALIGNMENT_CENTER,

title:'Privacidad/Seguridad',

font: 'Helvetica',

font: { fontSize:10 },

color:'White',

value:false,

width: 100 // necessary for textAlign to be effective

});

var TechosVerdesSwitch = Ti.UI.createSwitch({

style: Ti.UI.Android.SWITCH_STYLE_CHECKBOX,

textAlign:Ti.UI.TEXT_ALIGNMENT_CENTER,

title:'Techos verdes',

font: 'Helvetica',

font: { fontSize:10 },

color:'White',

value:false,

width: 100 // necessary for textAlign to be effective

});

var ControlErosionSwitch = Ti.UI.createSwitch({

style: Ti.UI.Android.SWITCH_STYLE_CHECKBOX,

textAlign:Ti.UI.TEXT_ALIGNMENT_CENTER,

title:'Control de Erosión',

font: 'Helvetica',

font: { fontSize:10 },

color:'White',

value:false,

width: 100 // necessary for textAlign to be effective

});

var EncintadosSwitch = Ti.UI.createSwitch({

style: Ti.UI.Android.SWITCH_STYLE_CHECKBOX,

textAlign:Ti.UI.TEXT_ALIGNMENT_CENTER,

title:'Encintados',

font: 'Helvetica',

font: { fontSize:10 },

color:'White',

value:false,

width: 100 // necessary for textAlign to be effective

});

var BonsaiSwitch = Ti.UI.createSwitch({

style: Ti.UI.Android.SWITCH_STYLE_CHECKBOX,

textAlign:Ti.UI.TEXT_ALIGNMENT_CENTER,

title:'Bonsai',

font: 'Helvetica',

font: { fontSize:10 },

color:'White',

value:false,

width: 100 // necessary for textAlign to be effective

});

var HuertosSwitch = Ti.UI.createSwitch({

style: Ti.UI.Android.SWITCH_STYLE_CHECKBOX,

textAlign:Ti.UI.TEXT_ALIGNMENT_CENTER,

title:'Huertos',

font: 'Helvetica',

font: { fontSize:10 },

color:'White',

value:false,

width: 100 // necessary for textAlign to be effective

});

var tablerows = [];

var tableView = Titanium.UI.createTableView({data:tablerows, height:620,bottom:-620});

// **************Here I use the array usosGen to define the switches I want to include:********

var numUsosGen = 15;

//var usosGen = ['TiestosSwitch', 'JardinerasSwitch','TopiariosSwitch',

// 'TrellisSwitch', 'TotemSwitch', 'TroncosSwitch',

// 'InteriorSwitch','CanastasSwitch', 'ParedesVerdesSwitch',

// 'PrivacidadSwitch','TechosVerdesSwitch', 'ControlErosionSwitch',

// 'EncintadosSwitch', 'BonsaiSwitch', 'HuertosSwitch'];

// I have tried the above as well, but does not work.<------

var usosGen = [TiestosSwitch, JardinerasSwitch,TopiariosSwitch,

           TrellisSwitch, TotemSwitch, TroncosSwitch,  

           InteriorSwitch,CanastasSwitch, ParedesVerdesSwitch,  

           PrivacidadSwitch,TechosVerdesSwitch, ControlErosionSwitch,  

           EncintadosSwitch, BonsaiSwitch, HuertosSwitch];   

var tableRows = [];

var switchesperrow = 3;

var numUsos=1;

//**********************Here I fill the rows of the table.*********************************

for (var numrows = 0; numrows < numUsosGen/switchesperrow; numrows++) {

var row= Titanium.UI.createTableViewRow({height:20, className:'row'});

for (var x = 0; x &lt; switchesperrow; x++) {

  if (numUsos &lt;= numUsosGen) {

     //var target=&quot;'&quot;+usosGen[numUsos]+&quot;'&quot;;\

            //I have tried the above as well ... but it won't work.

     var target=usosGen[numUsos];

     var alertDialog = Titanium.UI.createAlertDialog({

                    title: 'Adv Srch App',

                   message: 'The name of the desired switch to add to the row is: ' + target,

                    buttonNames: ['OK']

             });

             alertDialog.show(); 

     row.add(target);

     numUsos++;

   };
}
tablerows.push(row);   

};

tableView.add(tablerows);

view.add(tableView);


Viewing all articles
Browse latest Browse all 28

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>