Skip to main content

Titanium Appcelerator - Android and iPhone Application Development Part-2

If you are new in Titanium Appcelerator then check first part clickhere







create new file in main_windos folder name 'mainscreen.js';

put below code in login.js in button click


 loginButton.addEventListener('click',function(e){  
      if(username.value != '' && password.value != ''){  
           //alert("You are login!");  
           if(username.value == 'dhaval' && password.value == 'dhaval'){  
                loSubwin = Titanium.UI.createWindow({  
         url: 'mainscreen.js',  
         title: 'Home',  
         barColor:'#111'  
       });  
       Titanium.UI.currentTab.open(loSubwin,{animated:true});  
           }  
      }else{  
           alert("Please Enter User name & Password!");  
      }  
 });  


put below code in to 'mainscreen.js'


 var win = Titanium.UI.currentWindow;  
 var myCars = new Array();  
 myCars[0] = "Android";  
 myCars[1] = "iPhone";  
 myCars[2] = "Dhaval Sodha Parmar";  
 var comment = new Array();  
 comment[0] = "Google Product...";  
 comment[1] = "Apple Product...";  
 comment[2] = "DJ-Android";  
 var img = new Array();  
 img[0] = "http://im.tech2.in.com/gallery/2012/oct/android_42_251412547482_640x360.jpg";  
 img[1] = "http://images.macworld.com/images/article/2012/09/iphone5_large-294128.jpg";  
 img[2] = "https://lh4.googleusercontent.com/-Xky7Yh54i8c/AAAAAAAAAAI/AAAAAAAAAAA/nvx1glZaRvk/s48-c-k/photo.jpg";  
 //http://im.tech2.in.com/gallery/2012/oct/android_42_251412547482_640x360.jpg  
 //http://images.macworld.com/images/article/2012/09/iphone5_large-294128.jpg  
 //https://lh4.googleusercontent.com/-Xky7Yh54i8c/AAAAAAAAAAI/AAAAAAAAAAA/nvx1glZaRvk/s48-c-k/photo.jpg  
 function loadTweets() {  
      var rowData = [];  
      for (var i = 0; i < myCars.length; i++) {  
           var tweet = myCars[i];  
           // The tweet message  
           var user = comment[i];  
           // The screen name of the user  
           var avatar = img[i];  
           // The profile image  
           var row = Titanium.UI.createTableViewRow({  
                height : 50  
           });  
           // Create the view that will contain the text and avatar  
           var post_view = Titanium.UI.createView({  
                height : 'auto',  
                layout : 'vertical',  
                top : 5,  
                right : 5,  
                bottom : 5,  
                left : 5  
           });  
           // Create image view to hold profile pic  
           var av_image = Titanium.UI.createImageView({  
                url : avatar, // the image for the image view  
                top : 0,  
                left : 0,  
                height : 48,  
                width : 48  
           });  
           post_view.add(av_image);  
           // Create the label to hold the screen name  
           var user_lbl = Titanium.UI.createLabel({  
                text : user,  
                left : 54,  
                width : 120,  
                top : -48,  
                bottom : 2,  
                height : 16,  
                textAlign : 'left',  
                font : {  
                     fontFamily : 'Trebuchet MS',  
                     fontSize : 14,  
                     fontWeight : 'bold'  
                }  
           });  
           post_view.add(user_lbl);  
           // Create the label to hold the tweet message  
           var tweet_lbl = Titanium.UI.createLabel({  
                text : tweet,  
                left : 54,  
                top : 7,  
                bottom : 2,  
                height : 'auto',  
                width : 236,  
                textAlign : 'left',  
                font : {  
                     fontSize : 14  
                }  
           });  
           post_view.add(tweet_lbl);  
           // Add the post view to the row  
           row.add(post_view);  
           // Give each row a class name  
           row.className = "item" + i;  
           // Add row to the rowData array  
           rowData[i] = row;  
      }  
      // Create the table view and set its data source to "rowData" array  
      var tableView = Titanium.UI.createTableView({  
           data : rowData  
      });  
      //Add the table view to the window  
      win.add(tableView);  
 }  
 loadTweets();  

Run this app in to Android & iOS device check output.



Comments

Popular posts from this blog

Connecting mysql Database in ANDROID using PHP & JSON

 To implement this tutorial you should have basic knowledge of how to run PHP script and start server.  If we talk about client-server architecture, client is Android device and in server side there is a combination of PHP Script and MySQL. In short, PHP Script sits in middle as shown in image. Lets suppose that we have a MySQL database named Employee, and a table int created, with the following SQL: CREATE TABLE `employee` (   `emp_id` int(11) NOT NULL auto_increment,   `emp_name` varchar(100) NOT NULL,   PRIMARY KEY  (`emp_id`) ) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ; The PHP code will be very simple: Now Create Android Project :  The Android part is only a bit more complicated: -use a HttpPost to get the data -convert response to string -parse JSON data in to List In Your First Activity : O/P :

Multi-Selection ListView ANDROID with CheckBox PART-2

Check Below Code : mainActivity.java package com.example.listviewcheckbox; import java.util.ArrayList; import android.app.Activity; import android.content.Context; import android.graphics.Bitmap; import android.os.Bundle; import android.util.Log; import android.view.LayoutInflater; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.CheckBox; import android.widget.ImageView; import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; public class MainActivity extends Activity { private ListView listview; ArrayList<String> items = new ArrayList<String>(); private int count; private boolean[] thumbnailsselection; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(...

Android - Google MAP V2 PART 1

Download Full Code  of PART-1 , 2 , 3 , 4 Download and configure Google Play Services Library in Eclipse Google Map for Android is now integrated with Google Play Services. So we need to set up Google Play Service Library for developing Google Map application in Android. Get the API key for Google Maps v2: Linux  :  For any other OS use this :  keytool -list -v -alias androiddebugkey \ -keystore <path_to_debug_keystore>debug.keystore \ -storepass android -keypass android Register with the Google APIs Console :    Google APIs Console  Select here the  Services  entry: Activate the  Google Maps Android API v2 . Register your application via its package in this console together with the SHA-1 fingerprint of your signature key. Click on Create new Android Key.. Add you SHA-1 and your package name in to box like example given in alert box. Support library...