Building native apps with JavaScript: Titanium — Basic Todo App

Rene Pot
Rene Pot
Oct 23, 2017 · 6 min read
var window = Ti.UI.createWindow({
backgroundColor: "#cccccc",
title: 'Hi there!'
});
var mainWindow = window;
if (Ti.UI.iOS){
mainWindow = Ti.UI.iOS.createNavigationWindow({
window: window
});
}
mainWindow.open();

So what are we going to build?

Make a list

var list = Ti.UI.createTableView();
window.add(list);

Make an “add” button.

if (Ti.UI.iOS){
var addButton = Ti.UI.createButton({
title: 'Add'
});

window.rightNavButton = addButton;
}
else {
window.activity.onCreateOptionsMenu = function(e){
var addButton = e.menu.add({
title: "Add",
showAsAction : Ti.Android.SHOW_AS_ACTION_ALWAYS
});
};
}
if (Ti.UI.iOS){
var addButton = Ti.UI.createButton({
title: 'Add'
});
addButton.addEventListener('click', onClickAddButton);

window.rightNavButton = addButton;
} else {
window.activity.onCreateOptionsMenu = function(e){
var addButton = e.menu.add({
title: "Add",
showAsAction : Ti.Android.SHOW_AS_ACTION_ALWAYS
});
addButton.addEventListener('click', onClickAddButton);
};
}
mainWindow.open();function onClickAddButton(e){
alert('clicked!');
}

Conclusion

Patreon

All Titanium

Everything about App Development using Appcelerator Titanium

Rene Pot

Written by

Rene Pot

Developer Evangelist @ Appcelerator. Long time cross-platform mobile developer

All Titanium

Everything about App Development using Appcelerator Titanium