Skip navigation

Providing Feedback to the User

Providing Feedback to the User: Titanium Mobile App Development Essential Training
Providing Feedback to the User: Titanium Mobile App Development Essential Training

Join for an in-depth discussion in this video Providing Feedback to the User, part of Titanium Mobile App Development Essential Training.

Resume Transcript Auto-Scroll
Skill Level Beginner
3h 3m
Duration
261,759
Views
Show More Show Less

Q: I'm having trouble getting the code in the Chapter 5 "Opening windows from rows" movie to work for Android.

<div>A: There is a difference in the way&nbsp;Android treats a generic object that serves as data for a table. As well,&nbsp;there is no "hasDetail" property for Android table rows. The solution is to:</div><div>&nbsp;</div><div>1.) Rename all the "hasDetail" properties to "hasChild"&#8232;</div><div>2.) Instead of using generic objects in the data array, use Titanium Table&#8232;Row objects.</div><div>&nbsp;</div><div>As a general note: In order to attach custom properties to rows in Android,&nbsp;Titanium Table Row objects *must* be used. That isn't made clear in&nbsp;the Android docs, especially if the app won't fail if you don't do this&nbsp;as evidenced by the old code. New code is included here that should take care of this issue.</div><div>&nbsp;</div><div>This is how your code should read:</div><div>&nbsp;</div><span style="font-family: Courier;">// this sets the background color of the master UIView (when there are no windows/tab groups on it)</span><br /><span style="font-family: Courier;">Titanium.UI.setBackgroundColor('#000');</span><br /><br /><span style="font-family: Courier;">// create tab group</span><br /><span style="font-family: Courier;">var tabGroup = Titanium.UI.createTabGroup();</span><br /><br /><span style="font-family: Courier;">var win = Titanium.UI.createWindow({</span><br /><span style="font-family: Courier;">&nbsp;&nbsp;&nbsp; title:"Tours",</span><br /><span style="font-family: Courier;">&nbsp;&nbsp;&nbsp; backgroundColor:"#FFFFFF",</span><br /><span style="font-family: Courier;">&nbsp;&nbsp;&nbsp; //navBarHidden:true, //Hide the nav bar for the window</span><br /><span style="font-family: Courier;">&nbsp;&nbsp;&nbsp; tabBarHidden:true //Hide the tab bar for the window</span><br /><span style="font-family: Courier;">});</span><br /><span style="font-family: Courier;">//Remember, we are hiding this tab through the property tabBarHidden above</span><br /><span style="font-family: Courier;">var tab = Titanium.UI.createTab({</span><br /><span style="font-family: Courier;">&nbsp;&nbsp;&nbsp; icon:"KS_nav_views.png",</span><br /><span style="font-family: Courier;">&nbsp;&nbsp;&nbsp; title:"Tours",</span><br /><span style="font-family: Courier;">&nbsp;&nbsp;&nbsp; window:win</span><br /><span style="font-family: Courier;">});</span><br /><br /><span style="font-family: Courier;">var data = [</span><br /><span style="font-family: Courier;">&nbsp;&nbsp;&nbsp; Ti.UI.createTableViewRow({title:"Backpack Cal", leftImage:"images/01-backpack-cal-thumb.png", className:"tableRow"}),</span><br /><span style="font-family: Courier;">&nbsp;&nbsp;&nbsp; Ti.UI.createTableViewRow({title:"California Calm", leftImage:"images/02-calm-cal-thumb.png", className:"tableRow", hasChild:true, customData:"This is custom row data"}),</span><br /><span style="font-family: Courier;">&nbsp;&nbsp;&nbsp; Ti.UI.createTableViewRow({title:"California Hotsprings", leftImage:"images/03-hotsprings-cal-thumb.png", className:"tableRow"}),</span><br /><span style="font-family: Courier;">&nbsp;&nbsp;&nbsp; Ti.UI.createTableViewRow({title:"Cycle California", leftImage:"images/04-cycle-cal-thumb.png", className:"tableRow"}),</span><br /><span style="font-family: Courier;">&nbsp;&nbsp;&nbsp; Ti.UI.createTableViewRow({title:"From Desert to Sea", leftImage:"images/05-desert-cal-thumb.png", className:"tableRow"}),</span><br /><span style="font-family: Courier;">&nbsp;&nbsp;&nbsp; Ti.UI.createTableViewRow({title:"Kids California", leftImage:"images/06-kids-cal-thumb.png", className:"tableRow", hasChild:true, customData:"This is custom row data"}),</span><br /><span style="font-family: Courier;">&nbsp;&nbsp;&nbsp; Ti.UI.createTableViewRow({title:"Nature Watch", leftImage:"images/07-nature-watch-cal-thumb.png", className:"tableRow"}),</span><br /><span style="font-family: Courier;">&nbsp;&nbsp;&nbsp; Ti.UI.createTableViewRow({title:"Snowboard Cali", leftImage:"images/08-snowboard-cal-thumb.png", className:"tableRow",hasChild:true,js:"external.js",dataToPass:"This data was passed in from the main window"}),</span><br /><span style="font-family: Courier;">&nbsp;&nbsp;&nbsp; Ti.UI.createTableViewRow({title:"Taste of California", leftImage:"images/09-taste-cal-thumb.png", className:"tableRow"})</span><br /><span style="font-family: Courier;">];</span><br /><br /><br /><span style="font-family: Courier;">var tableView = Titanium.UI.createTableView({</span><br /><span style="font-family: Courier;">&nbsp;&nbsp;&nbsp; data:data</span><br /><span style="font-family: Courier;">});</span><br /><br /><span style="font-family: Courier;">tableView.addEventListener("click",function(e){</span><br /><span style="font-family: Courier;">&nbsp;&nbsp;&nbsp; //Check the row's hasDetail property</span><br /><span style="font-family: Courier;">&nbsp;&nbsp;&nbsp; var w;</span><br /><span style="font-family: Courier;">&nbsp;&nbsp;&nbsp; if(e.source.hasChild){</span><br /><span style="font-family: Courier;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(e.source.js){//Does the row have a pointer to an external js file?</span><br /><span style="font-family: Courier;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; //It does: Load that file</span><br /><span style="font-family: Courier;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; w = Titanium.UI.createWindow({</span><br /><span style="font-family: Courier;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; title:e.source.title,//Take the title from the row</span><br /><span style="font-family: Courier;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; backgroundColor:"#FFFFFF",</span><br /><span style="font-family: Courier;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dataToPass:e.source.dataToPass,</span><br /><span style="font-family: Courier;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; url:e.source.js//The url property of a window will load an external .js file for window contents (be sure that external file is properly formatted!)</span><br /><span style="font-family: Courier;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; });</span><br /><span style="font-family: Courier;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }else{</span><br /><span style="font-family: Courier;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; //It doesn't: Create a window from scratch</span><br /><span style="font-family: Courier;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; w = Titanium.UI.createWindow({</span><br /><span style="font-family: Courier;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; title:e.source.title,//Take the title from the row</span><br /><span style="font-family: Courier;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; backgroundColor:"#FFFFFF"</span><br /><span style="font-family: Courier;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; });</span><br /><span style="font-family: Courier;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; //Create some views for our window</span><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br /><span style="font-family: Courier;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; var label = Titanium.UI.createLabel({</span><br /><span style="font-family: Courier;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; text:"A newly opened window from the " + e.source.title + " row",</span><br /><span style="font-family: Courier;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; width:"auto",</span><br /><span style="font-family: Courier;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; height:"auto",</span><br /><span style="font-family: Courier;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; textAlign:"center"</span><br /><span style="font-family: Courier;">

Skills covered in this course
Developer Mobile Apps Mobile Web Web Titanium

Continue Assessment

You started this assessment previously and didn't complete it. You can pick up where you left off, or start over.

Start Your Free Trial Now

Start your free trial now, and begin learning software, business and creative skills—anytime, anywhere—with video instruction from recognized industry experts.

Start Your Free Trial Now