0% found this document useful (0 votes)
24 views19 pages

SynapseIndia Feedback For New Android Projects

The document provides step-by-step instructions for creating a new Android project in Eclipse, including selecting the project name, package name, and activity. It describes the project structure and key files like AndroidManifest.xml and strings.xml.

Uploaded by

synapseindia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views19 pages

SynapseIndia Feedback For New Android Projects

The document provides step-by-step instructions for creating a new Android project in Eclipse, including selecting the project name, package name, and activity. It describes the project structure and key files like AndroidManifest.xml and strings.xml.

Uploaded by

synapseindia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 19

SYNAPSEINDIA

FEEDBACK FOR NEW


ANDROID PROJECTS

CREATE A NEW ANDROID


PROJECT

From Eclipse, select File > New > Android Project.

Fill in the project details with the following values:


Project name: HelloAndroid
Application name: Hello, Android
Package name: com.example.helloandroid (or your own private
namespace)
Create Activity: HelloAndroid
Click Finish

CREATE A NEW
ANDROID
PROJECT

CREATE A NEW ANDROID


PROJECT

Project name - the name of the project


Package name - the name of the package.
This name will be used as the package name
in your Java files. Package name must be
fully qualified. The convention is to use your
company's domain name in reverse order
Activity name - the name of the activity in
your Android application. In Android, think
of an activity as a screen containing some
actions, hence the name "activity"
Application name - the user-friendly name
of the application that will be displayed in
the Applications tab of the Android UI
4

PACKAGE CONTENT

All source code here

All non-code
resources
Images

Java code for our activity

Generated Java code


Helps link resources to
Java code
Layout of the activity
Strings used in the
program
Android Manifest
5

THE VARIOUS FIELDS WHEN


CREATE A NEW ANDROID
PROJECT

First, the src folder contains your Java source files. The
HelloAndroid.java file is the source file for the HelloAndroid activity you
specified when you created the project earlier.

The R.java file is a special file generated by the ADT to keep track of all
the names of views, constants, etc, used in your Android project. You
should not modify the content of this file as its content is generated
automatically by the ADT.

The Android Library contains a file named android.jar. This file contains
all the classes that you would use to program an Android application.

The res folder contains all the resources used by your Android
application. For example, the drawable folder contains a png image file
that is used as the icon for your application. The layout folder contains
an XML file used to represent the user interface of your Android
application. The values folder contains an XML file used to store a list of
string constants.

The AndroidManifest.xml file is an application configuration file that


contains detailed information about your application, such as the
number of activities you have in your application, the types of
permissions your application needs, the version information of your
application, and so on.

RUN THE APPLICATION

The Eclipse plugin makes it easy to run your


applications:

Select Run > Run.


Select "Android Application".

/RES/LAYOUT/MAIN.XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/andro
id"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
</LinearLayout>

XML ATTRIBUTES

xmlns:android
This is an XML namespace declaration that tells the
Android tools that you are going to refer to common
attributes defined in the Android namespace. The
outermost tag in every Android layout file must have this
attribute.
android:id
This attribute assigns a unique identifier to the TextView
element. You can use the assigned ID to reference this
View from your source code or from other XML resource
declarations.
android:layout_width
This attribute defines how much of the available width
on the screen this View should consume. In this case, it's
the only View so you want it to take up the entire screen,
which is what a value of "fill_parent" means.
9

XML ATTRIBUTES

android:layout_height
This is just like android:layout_width, except that it
refers to available screen height.

android:text
This sets the text that the TextView should display.
In this example, you use a string resource instead of
a hard-coded string value. The hello string is defined
in the res/values/strings.xml file. This is the
recommended practice for inserting strings to your
application, because it makes the localization of your
application to other languages graceful, without
need to hard-code changes to the layout file.

10

/RES/VALUES/STRINGS.XML

In Android, the UI of each activity is represented using


various objects known as Views. You can create a view
using code, or more simply through the use of an XML file.
In this case, the UI Is represented using an XML file.
The <TextView> element represents a text label on the
screen while the <LinearLayout> element specifies how
views should be arranged.
Notice that the <TextView> element has an attribute
named android:text with its value set to "@string/hello".
The @string/hello refers to the string named hello defined
in the strings.xml file in the res/values folder.

<?xml version="1.0" encoding="utf-8"?>


<resources>
<string name="hello">Hello World, HelloAndroid!</string>
<string name="app_name">HelloAndroid</string>
</resources>

11

MODIFY STRINGS.XML
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello, Android! I am a string
resource!</string>
<string name="app_name">Hello, Android</string>
</resources>

12

RUN IT !

13

MODIFY THE MAIN.XML

Let's now modify the main.xml file. Add the following <Button> element:

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<Button
android:id="@+id/btnClickMe"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Click Me!"
/>
</LinearLayout>

14

RUN IT !

15

CONSTRUCT UI
package com.example.helloandroid;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class HelloAndroid extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
tv.setText("Hello, Android");
setContentView(tv);
}
}

16

RUN IT

17

R CLASS

In Eclipse, open the file named R.java (in the gen/ [Generated Java Files] folder).

The R.java file is a special file generated by the ADT to keep track of all the
names of views, constants, etc, used in your Android project. You should
not modify the content of this file as its content is generated automatically
by the ADT

package com.example.helloandroid;
public final class R {
public static final class attr {
}
public static final class drawable {
public static final int icon=0x7f020000;
}
public static final class id {
public static final int textview=0x7f050000;
}
public static final class layout {
public static final int main=0x7f030000;
}
public static final class string {
public static final int app_name=0x7f040001;
public static final int hello=0x7f040000;
}
}

18

ANDROIDMANIFEST.XML

The AndroidManifest.xml file is an application


configuration file that contains detailed information about
your application, such as the number of activities you have
in your application, the types of permissions your
application needs, the version information of your
application, and so on.

<?xml version="1.0" encoding="utf-8"?>


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.helloandroid"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".HelloAndroid"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

19

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy