I am trying to figure out how to make a multi-screen app using Appcelerator Titanium. I am familiar with Android development, so using the Android SDK I would create a few different activities, each doing their different work (login screen, screen displaying list of items, etc.) What is the equivalent in Titanium? I know that app.js is the main part of the app, but I assume it is not recommended to just put all code in that single file. The kitchen sink app has a lot of files and functionality, but I am not sure how they all fit together. So, what is the recommended way to create a project in Titanium for a basic app with a few screens doing different things? I am missing the Titanium concept of a screen.
Asked
Active
Viewed 9,064 times
5 Answers
2
App.js file is basically the file to initialize different window screens, and use Tabs to load those windows screens.Here is a link to create simple screens Create Window & Tabs
For further properties related to TitaniumUI

Muhammad Zeeshan
- 8,722
- 10
- 45
- 55
-
I can see how the windows are created there and moving between them with tabs, but what if I have an app without tabs. How can I have a button-click open a new window (leaving the previous window completely)? – Jake Mar 03 '11 at 21:50
-
You can can add the open new window code in the button click event.like: var open_window = Titanium.UI.createButton({ title:'Open a new window', top:170, left:30, right:30, height:30 }); open_window.addEventListener('click', function() { var newWindow = Titanium.UI.createWindow({ title:'New Window' }); Titanium.UI.currentTab.open(newWindow,{animated:true}); }); – Muhammad Zeeshan Mar 04 '11 at 04:55
-
1That looks more like what I was hoping for. So will that open a new window and dispose of the previous one (the one with the button on it), or will it just change the screen to cover the previous window with the new one on top of it? – Jake Mar 04 '11 at 16:34
-
1The new window will appear as the child window. It will have the Back button to go to Previous window. If you want multiple parent windows.. you need to make tabs for each window. – Muhammad Zeeshan Mar 05 '11 at 05:07
2
no..
you can do it like
var button = Ti.UI.createButton({..});
button.addEventListener('click',function(e){
var window = Ti.UI.createWindow({
url:"../newWindow.js",
title:"newWindow"
});
Titanium.UI.currentTab.open(window,{animated:true});
});
i recommend to use the MVC-pattern like i already posted here.
-
1Ok what if I don't use tabs? looks like all the examples I find around use tabs! and in my case the app is not using tabs. If I just create a new window and call its open method then it works, but as soon as the user presses the back button it gets thrown into the home screen as it actually never switched activities. It seems weird to me that no one has reported such a problem. – Bilthon Aug 09 '11 at 01:08
-
you need to behold it as hierachy. every window open call creates a new window context regardless of which way you open your window. if you want to have several windows concurrenty you need a tab bar. – mkind Aug 09 '11 at 13:24
-
Ok what if I don't use tabs? looks like all the examples I find around use tabs! and in my case the app is not using tabs. If I just create a new window and call its open method then it works, but as soon as the user presses the back button it gets thrown into the home screen as it actually never switched activities. It seems weird to me that no one has reported such a problem – Hikmat Khan Feb 16 '12 at 08:16
1
Try doing this:
app.js
Tintanium.include('window1.js', 'window2.js');
...
var button1 = Titanium.UI.createButton({...});
button1.addEventListener('click',function(){
window1.open();
});
window1.js
var window1=Titanium.UI.createWindow({...});
...etc...
Hope this will help ;)

Joan Méndez
- 11
- 1
0
After a lot of time research i i found the solution for opening different windows with a click event attached to a button.
employee.js
//Current window (employee window)
var employeeWin = Ti.UI.currentWindow;
//define button
var moveToDetailBtn = Ti.UI.createButton({
width : 200, //define the width of button
height : 50, //define height of the button
title : 'Show Detail' //Define the text on button
});
//Click event to open the Employee Details window
moveToDetailBtn.addEventListener('click', function(){
//Call a export function
var win = require('employeeDetails').getEmployeeDetailSWin;
//Create new instance
var employeeDetailsWin = new win();
//Open the Employee Details window
employeeDetailsWin.open();
});
//Add the button to the window
employeeWin.add(moveToDetailBtn);
In employeeDetails.js
exports.getEmployeeDetailSWin = function(){
//Creates a new window
var empDetailsWin = Ti.UI.createWindow({
backgroundColor : '#ffffff' //Define the backgroundcolor of the window
});
//Addin a label to the window
empDetailsWin.add(Ti.UI.createLabel({
width : 100, //Define width of the label
height : 50, //Define height of the label
title : 'Employee Details'
}));
return empDetailsWin;
};
I found the solution in this page: http://www.mindfiresolutions.com/Open-New-Window-Without-URL-Property-In-Titanium-2214.php

Mario Galván
- 3,964
- 6
- 29
- 39
0
try using my code below:
// functions
function openHomescreen(e)
{
settings.close();
getlucky.close();
survey.close();
homescreen.url = 'homescreen.js';
homescreen.open();
}
function openGetlucky(e)
{
settings.close();
homescreen.close();
getlucky.url = 'getlucky.js';
getlucky.open();
}
// events
Ti.App.addEventListener('homescreen',openHomescreen);
Ti.App.addEventListener('getlucky',openGetlucky);
openHomescreen({});
To open homescreen in other JS file, use this.
Ti.App.fireEvent('homescreen');

keithics
- 8,576
- 2
- 48
- 35