This tutorial shows how to create a tableview in Titanium and add data to it.
How to handle a click function in the tableView and get the data from the row.


   /* Create a new window */
   var win = Titanium.UI.createWindow({
			backgroundColor:'#336699',
			backgroundImage:'images/bkg.png',
			navBarHidden:true,
			tabBarHidden:true
	});

	/* Datasource for the tableView */
    var my_data = [
		{title:'data1'},
		{title:'data2'},
		{title:'data3'},
		{title:'data4'},
		{title:'data5'}
	];

    var tableview = Titanium.UI.createTableView({
		data:my_data,
		top:0
	});

	/* Alternately you can use this to set the datasource in the tableView.
	tableview.setData(my_data);
	*/

	/* this will handle the click function in the tableView */
	tableview.addEventListener('click', function(e)
	{
		e.rowData.hasCheck = true;		 // add a checkmark to the row.
		var title = e.rowData.title;	       // get the title property of the clicked row.
                var index = e.index;                     // got the clicked index;
                Ti.API.info("Clicked on index : " + index + "with row title : " + title);
	});

	win.add(tableview); 				// add the tableview to the window.

	win.open();							// open the window.

Please leave your valuable comments.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

 

 

 

Theme by HermesThemes

Copyright © 2018 CoderzHeaven. All Rights Reserved

Please wait...

Subscribe to our newsletter

Want to be notified when our article is published? Enter your email address and name below to be the first to know.