Android eclipse tutorial for beginners part1

Android eclipse tutorial for beginners part1

*    Go and download adt bundle which comes with eclipse and android sdk

*    Download java jdk if not already installed(check to see if java already installed, usually found at location c-program files-java)
*    Double click to open eclipse, it will ask you to specify the workstation on first time start up, specify this location properly(this is the location where your project contents are stored)
*    Now to set your android sdk location, in eclipse go to window-preferences

*    In the preferences window that opens select android from left sidebar, type in the sdk location(use browse option to navigate to the sdk folder in your computer)

*    Now that your sdk path is set, you are now all set to start developing your first android project.

Creating a new android project
*    In eclipse, go to File-New-Android Application Project.

*    In the New Android Application window that pops up, type an application name that starts in capital letter.

*    Now just click next until finish and click finish
*    This loads up your project packages in the left sidebar ( in the project explorer).

Getting to know your android application project files

To have a brief idea, we will now go through the important files on which you will be messing around to build a beginner project.

The source java files
Location     : In the project explorer (left sidebar)  ,  ”your app name”-src-com.example. ”your app name” -MainActivity.java
Use             : These are the java files which basically connect the app interfaces with each other and all the basic operations such as arithmetical operations, logical activities (if any).This means in order to handle any user given data, we need java files to specify how. The functions of the buttons, textboxes, spinners etc specified within the associated layout files are defined in this java file.
The layout files (xml files)
Location     : In the project explorer (left sidebar)  ,  ”your app name”-res-layout-activiy_main.xml
Use             : These are the design files where we can easily drag and drop the interfacing elements like buttons, edittexts, textboxes etc. Double clicking on the dragged elements will take you to the xml code for the selected element.
The manifest file
Location     : In the project explorer (left sidebar)  ,  ”your app name”-AndroidManifest.xml

Use             : This is an important file within your project package that maintains a sort of communication with your running hardware devices. It defines the activities (or simply the app windows /pages), permissions (suppose if your app is using permissions gps, internet) etc.
Creating a new Android Activity/App Window

*    Once you start developing your android app it is obvious that you will have to create more than one app windows.
*    In order to create a new app window/android activity,
·        go to your app on project explorer and right click

·        new-other-android activity
·        In the window that pops up , give the activity name and keep hitting next until finished

Creating a button onclick element to open up a new activity using intent


*    Once you have created your android project as described above, go to In the project explorer (left sidebar)  ,  ”your app name”-res-layout-activiy_main.xml
*    Switch to the graphical view in the bottom
*    Now drag and drop a button from the widgets option and double click the dragged button to open its xml code
*    Note down the button id from the xml code (just keep in mind).
*    Now go to the java file at        : In the project explorer (left sidebar)  ,  ”your app name”-src-com.example. ”your app name” -MainActivity.java
*    declare a new button(let it be Button b1;)
*    Now attach this button b1 to the button id earlier created in the layout file like this
b1=(Button)findViewById(R.id.button1);
Assuming the button id as button1.
Refer screenshots above.
*    Now to make the button to perform some task when clicked, type
b2.setOnClickListener(new OnClickListener() {
                    
                     @Override
                     public void onClick(View arg0) {
                           // TODO Auto-generated method stub
                           startActivity (new Intent (MainActivity.this, Addemp.class));

                     }
              });
Where  MainActivity is the current class(java file of current android activity) and Addemp.class is the java class of android activity which should be displayed on button click.



Comments