Android eclipse tutorial for beginners part1






Creating a new android
project




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


·
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







b1=(Button)findViewById(R.id.button1);
Assuming
the button id as button1.
Refer
screenshots above.

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
Post a Comment