ashok
Comments
Reactions

iPhone and Android application development using Titanium

By : Dheeraj Kumar Ketireddy

Titanium Mobile is Appcelerator's development platform for developing cross-platform native mobile applications. In this article we will be introducing you to installation and developing applications using Titanium.

Installation

Follow the steps mentioned here, to install Titanium and the corresponding sdks for your developement platform

Hello world application

Creating a new application and aplication structure is elaborately described in appcelerator gettting started guide

Creating Forms

Field Label

var win = Titanium.UI.currentWindow; // get refernce to the current window
var label = Titanium.UI.createLabel({
    text: 'Label Name',
    height: 50,
    color: '#000000',
    font:{fontSize:14},
    top: 20, // vertical postion of label on the screen w.r.t screen top
    left: 20, // horizontal postion of label on the screen w.r.t screen left
    width: 200 // width of the label
});
win.add(label); // add label to the current window

Check more properties of label in Titanium Label API

Text Field

var text_field = Titanium.UI.createTextField({
    color:'#000000',
    height: 50,
    top: 70, // vertical postion of label on the screen w.r.t screen top
    left: 20, // horizontal postion of label on the screen w.r.t screen left
    width: 200, // width of the field
    borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED
});
win.add(text_field); // add field to the current window

Check more properties of textfield in Titanium Text Field API

Button

var button = Titanium.UI.createButton({
    title: 'Button',
    top: 160, // vertical postion of label on the screen w.r.t screen top
    width: 200, // width of the button
    height: 50 // width of the button
});
win.add(button); // add button to the current window

Check more properties of button in Titanium Button API

Submiting Form Data

Form submission has to be handled via 'click' event listner on button

button.addEventListener('click', function() { 
    var field_value = text_field.value;
});

Screenshot of how the form with the above code looks Screenshot of form

Accessing database and saving data to database is mentioned in the next section.

Database

Creating database

var db = Titanium.Database.open('db_name');

'open' returns a reference to the opened database. If the database doesn't yet exist, 'open' creates the database.

Executing SQL queries

db.execute('CREATE TABLE IF NOT EXISTS table_name (id INTEGER PRIMARY KEY, field1 VARCHAR, field2 VARCHAR);');

Inserting data into table

var f1 = 'v1';
var f2 = 'v2';
db.execute('INSERT INTO table_name (f1, f2) VALUES (?, ?)', f1, f2);

Id of last inserted row is the value of 'lastInsertRowId' property on the database var last_insert_id = db.lastInsertRowId;

Selecting and looping over the data from table

var rows = db.execute('select * from table_name');

while (rows.isValidRow()) {
    // check below on how to access field values of a row
    rows.next();
}
rows.close();

Accessing the field values of a row by index(zero based)

var id = rows.field(0);
var v1 = rows.field(1);
var v2 = rows.field(2);

Accessing the field values of a row by name

var id = rows.fieldByName('id');
var v1 = rows.fieldByName('field1');
var v2 = rows.fieldByName('field2');

More about Database API

  • Titanium.Database.install('meditracker');, raised invalid database path error when tried to run the application on device. So I opted to use Titanium.Database.open

Code Resources

Related Posts


Can we help you build amazing apps? Contact us today.

Comments

rosetta stone


Rosetta Stone is proprietary language-learning software produced by Rosetta Stone;Ltd. Its title and its logo refer to the Rosetta Stone , an artifact inscribed in multiple languages that helped Jean-Fran?ois Champollion to decipher Egyptian hieroglyphics.
The Rosetta Stone software uses a combination of images, text, and sound, with difficulty levels increasing as the student progresses, in order to teach various vocabulary terms and grammatical functions intuitively, without drills or translation. They call this the Dynamic Immersion method;. The goal is to teach languages the way first languages are learned.Now,the Rosetta Stone;Ltd have several kinds of the Rosetta Stone language on sale,such as Rosetta Stone Spanish,Rosetta Stone German and Rosetta Stone Italian, these Rosetta Stone Languages are very popular now!

commmenttor
Conor Clafferty

For any beginners looking at starting app development with titanium they should check out the TiBountyHunter app. This is the app that you will build during the Titanium Certified App Developer Training and is provided on the appcelerator website.

Unlike the KitchenSink App, the TiBountyHunter app shows you how to structure your code properly. This is in my opinion one of the best lessons as a messy app will no doubt be a nightmare to maintain in the future.

commmenttor
Ashish

Hey Ashok,
How can i save datetime.now() in my localDB ??
I'm developing an sample app,
Which can sends a message to Server(djangoApp-API support) and saves the message into local-db(mobile App) simultaneously.

commmenttor
Jacob Dixon

Titanium seems to be a useful tool and tutorial over here is very nice to understand and go follow each and every steps of installation of Titanium, Can you please reply regarding the different features about it.

commmenttor
Deyvid Nascimento

Hi,
I'm searching application titanium mobile apps, you have any application in market or apple store? Which the link?

commmenttor
Android app builder

Really a useful resource and very informative...!!

commmenttor
harish

I am unable to fetch the data from database in android mobile using titanium studio. the same code should worked in web browsers.

commmenttor
subash

I need mouse on over event Listener for Android development by Using Titanium

commmenttor
iphone application development

wow this is very cool i like climate change and study for a long time wow this is exactly what i mean and what i looking for i am so grateful thanks.

commmenttor
iPhone App Developer

Ashok , Thanks with regards for A real useful resource and very informative...!!

commmenttor
Blake Edwards

This is the app that you will develop during the Titanium Qualified App Designer Exercising and is offered on the app accelerator web page.

commmenttor
Paul Rogers

Your way of describe use of Titanium for application development is simply nice. The link which you provide for installing Titanium is helpful to beginners who don't know how to start up with this tool.

commmenttor
Phelan Flynn

This is the app that you will create during the Titanium Certified App Developer Training and is provided on the app decrease website.

commmenttor
iphone app developer

I have a Titanuim application and I want to put few UI screens.how can i do that? can anyone advise?

commmenttor
android app development

Ashok love your blog and the information you've provide about iPhone and android app development using Titanium is so informative! Thanks for sharing such a great tips...

commmenttor
ray ban sunglasses

test awdio. comits a big dj web page.. a lttle bit diff compared to radios upon the following but nonetheless awesome Try out filtermusic. internet that is a assortment of a lot of online broadcasts.
ray ban sunglasses http://www.sunglassesoutlettop.com

commmenttor

Reactions

proggitarticles

iPhone and Android application development using Titanium: submitted by shabda [link] [comment] http://bit.ly/fJEmov

commmenttor
agiliqdotcom

iPhone and Android app development using Titanium http://agiliq.com/blog/2011/02/iphoneandroid-application-development-using-titani/

commmenttor
theju

RT@agiliqdotcom: iPhone and Android app development using Titanium http://agiliq.com/blog/2011/02/iphoneandroid-application-development-using-titani/

commmenttor
Mahmkamal

Easy iphone , android Development using #Titanium@appcelerator http://bit.ly/jWxe8t

commmenttor
Mahmkamal

Easy iphone , android application Development using #Titanium@appcelerator http://bit.ly/jWxe8t

commmenttor
Post a comment Name :

Email :

Your site url:

Comment :

© Agiliq, 2009-2012