<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-1502575668589055594</id><updated>2024-08-29T14:38:38.069-07:00</updated><category term="An introduction to Android by Arif Nadeem"/><category term="Android"/><title type='text'>Android - An Introduction</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://android-development-series-by-arif.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1502575668589055594/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://android-development-series-by-arif.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/07907058669445568514</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>1</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-1502575668589055594.post-2459269493354340863</id><published>2012-02-18T15:53:00.000-08:00</published><updated>2012-02-22T06:32:53.567-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="An introduction to Android by Arif Nadeem"/><category scheme="http://www.blogger.com/atom/ns#" term="Android"/><title type='text'>An Introduction to Android development</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Hello all, this article is the first of the series of articles that I intend to write in future.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;Note: For the purpose of this tutorial, I assume that you have working knowledge of Java programming language.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;u&gt;So what is Android?&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #333333; font-family: arial, sans-serif; font-size: 13px; line-height: 16px; text-align: -webkit-auto;&quot;&gt;&lt;i&gt;&lt;b&gt;&quot;Android is a software stack for mobile devices that includes an operating system, middleware and key applications.&quot;&lt;/b&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
This is the quote which you will find at &lt;a href=&quot;http://developer.android.com/guide/basics/what-is-android.html&quot;&gt;Android developers page&lt;/a&gt; which Google tells us what android is. You can read the theory of Android on their developers site.&lt;br /&gt;
&lt;br /&gt;
Android applications are written by using Java and its UI (User interface) is written in XML.&lt;br /&gt;
&lt;br /&gt;
In order to start writing Android applications you would have to download, JDK (Java development kit), Eclipse (A simple and good IDE), Android SDK and ADT plugin.&lt;br /&gt;
&lt;br /&gt;
You can click on the following links to download these, remember these are individual components and all of them are necessary to write apps for Android.&lt;br /&gt;
&lt;br /&gt;
1. Firstly download JDK, as of now Java 7 is not compatible with Android so you would have to settle down with Java 6, click the appropriate link, i.e if your Desktop OS is Windows 7 64 Bit select &quot;&lt;a href=&quot;http://www.oracle.com/technetwork/java/javase/downloads/jdk-6u31-download-1501634.html&quot; id=&quot;jdk-6u31-oth-JPRXXXjdk-6u31-windows-x64.exe&quot; name=&quot;jdk-6u31-oth-JPRXXXjdk-6u31-windows-x64.exe&quot; style=&quot;background-color: white; color: red; font-family: arial, helvetica, sans-serif; font-size: 12px; list-style-image: initial; list-style-position: initial; list-style-type: none; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;jdk-6u31-windows-x64.exe&lt;/a&gt;&quot;&amp;nbsp;as your option, if it is not, then find it &lt;a href=&quot;http://www.oracle.com/technetwork/java/javase/downloads/jdk-6u31-download-1501634.html&quot;&gt;here&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
2. Download Eclipse, eclipse is an IDE which stands for Integrated Development Environment, it is helpful when you program as it helps you in&amp;nbsp;organizing&amp;nbsp;your code, it provides you with hints while you type your code and they are many more benefits of using it, to download eclipse visit this &lt;a href=&quot;http://www.eclipse.org/downloads/&quot;&gt;page&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
3. Install Android SDK using this &lt;a href=&quot;http://developer.android.com/sdk/index.html&quot;&gt;link&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
4. Finally install the ADT plugin which can be done if you follow the steps shown &lt;a href=&quot;http://developer.android.com/sdk/eclipse-adt.html&quot;&gt;here&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
This &lt;a href=&quot;http://www.talkandroid.com/guides/developer/android-sdk-install-guide/#.T0AMvYexbpg&quot;&gt;link&lt;/a&gt; will provide you with the detailed instructions of how to set up the Android development platform.&lt;br /&gt;
&lt;br /&gt;
After setting up the platform open eclipse.exe and you should be good to start, your eclipse window will look something like this&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEia6MCl66CfUDoh84V3xghQ9f1wAXPoztYSceYiR_Wqr_hIbsxVDkZVmZ_kzUSJS8an2L3yWBlqqFQOMvYVUMxq52QFRKurWdB_hyphenhyphenDcFjC-geU8h5uhSl86Itha1Ot4L4kxDO5zv9gG5WUL/s1600/Eclipsescreenshot.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;180&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEia6MCl66CfUDoh84V3xghQ9f1wAXPoztYSceYiR_Wqr_hIbsxVDkZVmZ_kzUSJS8an2L3yWBlqqFQOMvYVUMxq52QFRKurWdB_hyphenhyphenDcFjC-geU8h5uhSl86Itha1Ot4L4kxDO5zv9gG5WUL/s320/Eclipsescreenshot.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Click on File -&amp;gt; New -&amp;gt; Project -&amp;gt; Android Project and you should see this.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiXUwtjHosdYfmZjiNYyNwhpo5zw2fVXKyHtVLjbtuavdUx2T-pBSCYLBq3GlQsEeEUaMPIn_Jqk5zVtR69iSw7ner0EerbI0LbPXL3GKS56GglrPabkxoMHXfzGv8ZCHnaqqi5RpPu6iHQ/s1600/androidnew.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;180&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiXUwtjHosdYfmZjiNYyNwhpo5zw2fVXKyHtVLjbtuavdUx2T-pBSCYLBq3GlQsEeEUaMPIn_Jqk5zVtR69iSw7ner0EerbI0LbPXL3GKS56GglrPabkxoMHXfzGv8ZCHnaqqi5RpPu6iHQ/s320/androidnew.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Type the name of the project in the Project Name text box and check Create new project in workspace option, I named my project as Counter click next and you will see this.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgovFxWILQQv7D-4CrnVZRehki9qO_PNoDT7wC4HSeJwjMaZ5cTiDdL7lEHW5hDjW-vQ0gEpwBq9svQ9S_sFav4U2432uGqJ8yem1FH3W8Lkd-SuvS4O14VYjdadNoDCsLDveZmIL1W4eK1/s1600/selectsdk.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;180&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgovFxWILQQv7D-4CrnVZRehki9qO_PNoDT7wC4HSeJwjMaZ5cTiDdL7lEHW5hDjW-vQ0gEpwBq9svQ9S_sFav4U2432uGqJ8yem1FH3W8Lkd-SuvS4O14VYjdadNoDCsLDveZmIL1W4eK1/s320/selectsdk.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Select the SDK that you want your app to be built for. I am selecting Android 4.0. Click next.&lt;br /&gt;
&lt;br /&gt;
Next you will see this.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVmv727OrhgHoywy185i0qlBvkMHmbvjRQEoObv8JZkGo6vCrzD3FVs1roYJKS7CkRPsQYSDzDeGU2qModV3_ZRWPdlOeZyB-e1er9zUCHzOiNu8ohiRQVdADelJC6szUBSn9S1QvxEynD/s1600/simplecounter.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;180&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVmv727OrhgHoywy185i0qlBvkMHmbvjRQEoObv8JZkGo6vCrzD3FVs1roYJKS7CkRPsQYSDzDeGU2qModV3_ZRWPdlOeZyB-e1er9zUCHzOiNu8ohiRQVdADelJC6szUBSn9S1QvxEynD/s320/simplecounter.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
The first field is your Application&#39;s name, in my case Counter, next field is package name, the naming convention that all Android developers follow is com.yourname.packagename, your package name must have two identifiers, I had named my project as com.arif.SimpleCounter, remember it is a convention to name packages starting with com.&lt;br /&gt;
&lt;br /&gt;
Next field specifies your Activity&#39;s name, now an activity is the single screen which the user sees when he interacts with your &amp;nbsp;application. An example to illustrate this is, when you look at your contacts in your phone, you are looking at one particular screen, that is called as an activity which is a term we use in Android development, become familiar with it as it is what you probably will call it the rest of your life, for more on Activity refer to Android developers site. The first activity is named automatically by Eclipse.&lt;br /&gt;
&lt;br /&gt;
The last field is the API level which corresponds to your SDK, it is 14 in case of Android 4.0.&lt;br /&gt;
Click finish when you are done and you will see a project created under package explorer.&lt;br /&gt;
&lt;br /&gt;
It is important that you understand the folder structure of an Android application in order to be a good application developer, here is where your code and other resources are organised, beware it is very tricky, but with practice you will be fine, now expand your project and you will see this.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgFuH_r8c1miVjtKycVCrL05BzPoP615_g_4X891LKHTojTdx_6QobJQjNd60PB1-fuabAKj0Rs0jdJO48HujXA8IsAy-brQ3sasY-jIl-BdE2M11hsmDcRq9DcYZa7S_n1nUk97UyfiWKb/s1600/folderstructure.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgFuH_r8c1miVjtKycVCrL05BzPoP615_g_4X891LKHTojTdx_6QobJQjNd60PB1-fuabAKj0Rs0jdJO48HujXA8IsAy-brQ3sasY-jIl-BdE2M11hsmDcRq9DcYZa7S_n1nUk97UyfiWKb/s320/folderstructure.png&quot; width=&quot;128&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
The first folder &lt;b&gt;src &lt;/b&gt;that you see is where you write your java code, it can contain many packages, in our case it is just one i.e. com.arif.SimpleCounter, but in practical app development scenarios they can be dozens of packages. The package themselves contain Java classes, again in practical scenario each package may contain hundreds of Java Classes. For now just remember that we write our programs in &quot;src&quot; folder.&lt;br /&gt;
&lt;br /&gt;
Next is &lt;b&gt;gen&lt;/b&gt; folder, this is generated automatically as you write the code and build it, DO NOT MAKE ANY&amp;nbsp;MODIFICATIONS TO R.Java class, your compiler does this automatically for you.&lt;br /&gt;
&lt;br /&gt;
Next folder is Android 4.0, it contains all the Android libraries that you will need in your app development.&lt;br /&gt;
&lt;br /&gt;
Folder &amp;nbsp;&lt;b&gt;bin &lt;/b&gt;contains your .apk, .dex and resources.ap_ files, these are all important so that your app can be installed on android devices, we will see what .dex and .apk files are in future.&lt;br /&gt;
&lt;br /&gt;
Next folder &lt;b&gt;res &lt;/b&gt;is where we place all our project resources like images, audio files, styling xml files etc. It contains five folders &lt;b&gt;drawables (hdpi, mdpi, ldpi)&lt;/b&gt;,&lt;b&gt; layout&lt;/b&gt; and &lt;b&gt;values&lt;/b&gt;. Drawable folders are used to place images that can be set as say background for our activity.&lt;br /&gt;
&lt;br /&gt;
Folder &lt;b&gt;layout &lt;/b&gt;contains all the xml files which we use to create our UI. In our case we see a main.xml file in which we will create a layout of our application.&lt;br /&gt;
&lt;br /&gt;
Folder &lt;b&gt;values &lt;/b&gt;contain xml file called strings.xml, this is a way android developers use to refer to static strings that will be utilized by the app, you can write names for e.g. say your app&#39;s name, or your button&#39;s name etc. The advantage of writing names in this folder is that they will be localized automatically depending on the users location, for e.g. consider that you have written your app in English and&amp;nbsp;you used strings.xml to name your app or your UI components, now if a person in France downloads your app he would see that names in French. So it is a good practice to use strings.xml to name your components.&lt;br /&gt;
&lt;br /&gt;
Next file is the AndroidManifest.xml file, this is an important part, this tells as of what activities you use, Ill tell you more about activities in my next blog, manifest file holds record of all the activities contained in your application. It also tells as of what permissions you app uses for user to grant it, for e.g. your app may contain&lt;br /&gt;
permission to access gps or internet etc. It also tells on which version of Android can your app be installed on.&lt;br /&gt;
Android market reads Manifest file to determine whether the app can be installed on your device.&lt;br /&gt;
&lt;br /&gt;
This was pretty much about the folder structure of an Android app.&lt;br /&gt;
&lt;br /&gt;
Now let us dive straight into writing our first app...&lt;br /&gt;
&lt;br /&gt;
Open &lt;b&gt;main.xml&lt;/b&gt; which is under the &lt;b&gt;layout&lt;/b&gt; folder, you will see two perspectives one is the graphical design of the view and other is the xml code.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&amp;gt;&lt;br /&gt;
&amp;lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; android:layout_width=&quot;fill_parent&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; android:layout_height=&quot;fill_parent&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; android:orientation=&quot;vertical&quot; &amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;TextView&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_width=&quot;fill_parent&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_height=&quot;wrap_content&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:text=&quot;@string/hello&quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/LinearLayout&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here lie two things of our interest, the first one is our LinearLayout, it is how your UI components be placed in your activity, in this case we tell android that we want to lay our UI elements linearly i.e. either horizontally or vertically. LinearLayout specifies some properties like &amp;nbsp;android:layout_width=&quot;fill_parent&quot;,&amp;nbsp;android:layout_height=&quot;fill_parent&quot;,&amp;nbsp; android:orientation=&quot;vertical&quot; etc.&lt;br /&gt;
&lt;br /&gt;
Layout width property specifies as of how wide you want your layout to be, in our case we tell it to be as wide as the screen is, similar case is with layout height property, we tell it to cover up the entire height of the screen.&lt;br /&gt;
&lt;br /&gt;
Every element in the xml file is enclosed within a starting and ending tag like this &amp;lt;LinearLayout&amp;gt;&amp;lt;/LinearLayout&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The second element in our xml file is a TextView, it is used for displaying text, in our case it displays @string/hello by default, look how TextView is enclosed in tags and in turned in&amp;nbsp;sandwiched or nested between LinearLayout&#39;s starting&amp;nbsp;and ending tag, this is how xml files are written.&lt;br /&gt;
&lt;br /&gt;
I modify my main.xml as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&amp;gt;&lt;br /&gt;
&amp;lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; android:layout_width=&quot;fill_parent&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; android:layout_height=&quot;fill_parent&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; android:orientation=&quot;vertical&quot; &amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;TextView&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_width=&quot;fill_parent&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_height=&quot;wrap_content&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_gravity=&quot;center&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_marginTop=&quot;40dp&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:gravity=&quot;center&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:id=&quot;@+id/ourTextView&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:text=&quot;Your Count is 0&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:textColor=&quot;#00FFFF&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:textSize=&quot;26dp&quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;Button&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_width=&quot;250dp&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_height=&quot;wrap_content&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_gravity=&quot;center&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_marginTop=&quot;40dp&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:gravity=&quot;center&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:id=&quot;@+id/btnIncrement&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:text=&quot;Increment&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:textSize=&quot;22dp&quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;Button&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_width=&quot;250dp&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_height=&quot;wrap_content&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_gravity=&quot;center&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:layout_marginTop=&quot;30dp&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:id=&quot;@+id/btnDecrement&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:gravity=&quot;center&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:text=&quot;Decrement&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:textSize=&quot;22dp&quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/LinearLayout&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
I modified my TextView and included many properties like layout_gravity which tells it to center itself, then I changed the color and size of the text. The property layout_marginTop tells TextView to be &amp;nbsp;at 40 dp &amp;nbsp;from its top, the properties&amp;nbsp;&amp;nbsp;android:gravity=&quot;center&quot;,&amp;nbsp;android:text=&quot;Your Count is 0&quot;, tells it to position the text at center and I set it text in android:text, I am hardcoding the text for now, in later tutorials I&#39;ll show you as of how to use strings.xml, but for now do it my way.&lt;br /&gt;
&lt;br /&gt;
Next I include two buttons named &quot;Increment&quot; and &quot;Decrement&quot;, which I had named on the operation which they are supposed to perform, have a closer look at the properties I have used, you can include many other properties, but for this demo I think those are enough. It is good if you investigate more properties.&lt;br /&gt;
&lt;br /&gt;
The UI elements button and textview are derived from a class named View, every basic UI element is derived from view, generally speaking, every UI element that you see in Android can be termed as a View.&lt;br /&gt;
&lt;br /&gt;
Your graphical layout of main.xml file should look something like this.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjEn9HblYf04-9jZBpEtPzpg8yEDm4YOtyWynnQUOC0qHrim3fogxNgFPL13P12w82n1JJpO4mZqvBgc3nTnhNM_lR88anUSPC6x80AMPc18p9IZM2FN59Sk9GOofzXZt53JwvS9RCqkprI/s1600/scrrenshot.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjEn9HblYf04-9jZBpEtPzpg8yEDm4YOtyWynnQUOC0qHrim3fogxNgFPL13P12w82n1JJpO4mZqvBgc3nTnhNM_lR88anUSPC6x80AMPc18p9IZM2FN59Sk9GOofzXZt53JwvS9RCqkprI/s320/scrrenshot.png&quot; width=&quot;199&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Now you are good enough to run you application, but wait, what will happen if I click the two buttons?&lt;br /&gt;
The answer is nothing, as we haven&#39;t written any logic to tell the buttons as of what to do when we click them.&lt;br /&gt;
&lt;br /&gt;
This is an interesting aspect of Android platform, we design our UI differently in most of the cases and then write logic to tell those UI elements as of what to do when we interact with them, in our case we have designed our UI in main.xml file and now we want to tell the buttons to increment or decrement the value of count when we press them, this is done in CounterActivity.java file, double click to open it.&lt;br /&gt;
&lt;br /&gt;
You will see this.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
package com.arif.SimpleCounter;&lt;br /&gt;
&lt;br /&gt;
import android.app.Activity;&lt;br /&gt;
import android.os.Bundle;&lt;br /&gt;
&lt;br /&gt;
public class CounterActivity extends Activity {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; /** Called when the activity is first created. */&lt;br /&gt;
&amp;nbsp; &amp;nbsp; @Override&lt;br /&gt;
&amp;nbsp; &amp;nbsp; public void onCreate(Bundle savedInstanceState) {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; super.onCreate(savedInstanceState);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; setContentView(R.layout.main);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Our class CounterActivity extends Activity, which is a base class that most apps use and derive from, it contains many predefined methods written by software developers at Google for our&amp;nbsp;convenience.&lt;br /&gt;
&lt;br /&gt;
In it is an overriden method &lt;b&gt;onCreate&lt;/b&gt;, this method is called when your activity is first created, it is important to know the life-cycle of an android app which I hopefully will discuss in the next few tutorials.&lt;br /&gt;
The method&amp;nbsp;setContentView(R.layout.main) sets UI that we created in main.xml file as the activity&#39;s View content.&lt;br /&gt;
&lt;br /&gt;
I modify my code as follows&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
public class CounterActivity extends Activity {&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;/** Called when the activity is first created. */&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Button btnIncrement, btnDecrement;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;TextView tvOurTextView;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;int count;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;@Override&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;public void onCreate(Bundle savedInstanceState) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;super.onCreate(savedInstanceState);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;setContentView(R.layout.main);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;btnIncrement = (Button) findViewById(R.id.btnIncrement);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;btnDecrement = (Button) findViewById(R.id.btnDecrement);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;tvOurTextView = (TextView) findViewById(R.id.ourTextView);&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;btnIncrement.setOnClickListener(new View.OnClickListener() {&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;public void onClick(View v) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;count++;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;tvOurTextView.setText(&quot;Your Count is &quot; + count);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;});&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;btnDecrement.setOnClickListener(new View.OnClickListener() {&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;public void onClick(View v) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;count--;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;tvOurTextView.setText(&quot;Your Count is &quot; + count);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;});&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
I declared Button, TextView and count as global variables, doing so helps us in using them in different methods, next in onCreate method we would have to reference our buttons and textview with those in our xml file, that is why we had to use android:id property in our xml file, this is because we would have to reference back those views in our java code, consider this you might create a 100 views in your xml file but you would have to identify them uniquely so findViewById fulfills that purpose.&lt;br /&gt;
&lt;br /&gt;
The next two methods are used to set on Click liseners to our buttons, as you would expect a user to click a button and see a result. In the&amp;nbsp;setOnClickListener for btnIncrement, we increment count by one everytime the user clicks it and viceversa for btnDecrement.&lt;br /&gt;
&lt;br /&gt;
Finally we use setText method on our TextView to set it text to what ever the value if the count is when you click the button.&lt;br /&gt;
&lt;br /&gt;
Your final app will look like this:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgEk3Ijmmm6AaSEiB8o1EjI-Z9QFzXllBQmE09gZkexafJPi5d3bGmwfW3BacbFI3ioWJEYlxO445N4JJ7vjNOpnEALihq-zT1EwXa7gGGh06_91CoNFAw6SUxtAAM9LwP8Kgc_4inMeLW_/s1600/incrcount.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgEk3Ijmmm6AaSEiB8o1EjI-Z9QFzXllBQmE09gZkexafJPi5d3bGmwfW3BacbFI3ioWJEYlxO445N4JJ7vjNOpnEALihq-zT1EwXa7gGGh06_91CoNFAw6SUxtAAM9LwP8Kgc_4inMeLW_/s320/incrcount.png&quot; width=&quot;215&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://2.bp.blogspot.com/-71_P7lTRom0/T0A9sWAesjI/AAAAAAAAAN8/19xIMGxYpz0/s1600/decrcount.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;http://2.bp.blogspot.com/-71_P7lTRom0/T0A9sWAesjI/AAAAAAAAAN8/19xIMGxYpz0/s320/decrcount.png&quot; width=&quot;214&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Hurray! that is it. Now you can run your app and yes it fully functional, you can increase your count or decrease it. As a matter of fact you can deploy it to Android market if you have a developer account.&lt;br /&gt;
&lt;br /&gt;
I hope you understood the basic mechanics of Android development.&lt;br /&gt;
&lt;br /&gt;
But wait this app isn&#39;t complete yet, hit ctrl+F11 if you are on windows or&amp;nbsp;&lt;span style=&quot;background-color: white; font-family: Arial, &#39;Liberation Sans&#39;, &#39;DejaVu Sans&#39;, sans-serif; font-size: 14px; line-height: 18px;&quot;&gt;ctrl+fn+F11 on Mac.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: Arial, &#39;Liberation Sans&#39;, &#39;DejaVu Sans&#39;, sans-serif; font-size: 14px; line-height: 18px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: Arial, &#39;Liberation Sans&#39;, &#39;DejaVu Sans&#39;, sans-serif; font-size: 14px; line-height: 18px;&quot;&gt;What do you see?&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: Arial, &#39;Liberation Sans&#39;, &#39;DejaVu Sans&#39;, sans-serif; font-size: 14px; line-height: 18px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: Arial, &#39;Liberation Sans&#39;, &#39;DejaVu Sans&#39;, sans-serif; font-size: 14px; line-height: 18px;&quot;&gt;Alas the value of Count is lost, this is because the activity is refreshed when it is switched from Portrait mode to Landscape mode and vice-versa.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: Arial, &#39;Liberation Sans&#39;, &#39;DejaVu Sans&#39;, sans-serif; font-size: 14px; line-height: 18px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: Arial, &#39;Liberation Sans&#39;, &#39;DejaVu Sans&#39;, sans-serif; font-size: 14px; line-height: 18px;&quot;&gt;So how do you go about it? How would you save the application&#39;s state?&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: Arial, &#39;Liberation Sans&#39;, &#39;DejaVu Sans&#39;, sans-serif; font-size: 14px; line-height: 18px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: Arial, &#39;Liberation Sans&#39;, &#39;DejaVu Sans&#39;, sans-serif; font-size: 14px; line-height: 18px;&quot;&gt;I will show you that in the next tutorial.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: Arial, &#39;Liberation Sans&#39;, &#39;DejaVu Sans&#39;, sans-serif; font-size: 14px; line-height: 18px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: Arial, &#39;Liberation Sans&#39;, &#39;DejaVu Sans&#39;, sans-serif; font-size: 14px; line-height: 18px;&quot;&gt;Stay Tuned.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: Arial, &#39;Liberation Sans&#39;, &#39;DejaVu Sans&#39;, sans-serif; font-size: 14px; line-height: 18px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, &#39;Liberation Sans&#39;, &#39;DejaVu Sans&#39;, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 18px;&quot;&gt;Please leave your feedbacks.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://android-development-series-by-arif.blogspot.com/feeds/2459269493354340863/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://android-development-series-by-arif.blogspot.com/2012/02/introduction-to-android-development.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1502575668589055594/posts/default/2459269493354340863'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1502575668589055594/posts/default/2459269493354340863'/><link rel='alternate' type='text/html' href='http://android-development-series-by-arif.blogspot.com/2012/02/introduction-to-android-development.html' title='An Introduction to Android development'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/07907058669445568514</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEia6MCl66CfUDoh84V3xghQ9f1wAXPoztYSceYiR_Wqr_hIbsxVDkZVmZ_kzUSJS8an2L3yWBlqqFQOMvYVUMxq52QFRKurWdB_hyphenhyphenDcFjC-geU8h5uhSl86Itha1Ot4L4kxDO5zv9gG5WUL/s72-c/Eclipsescreenshot.png" height="72" width="72"/><thr:total>0</thr:total></entry></feed>