Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
50 views

Android Document: How To Create A New Project?

To create a new Android project, open Eclipse, go to File > New > Android Project, enter a project name and select build options. An Android app contains an Activity class that extends Activity and overrides onCreate to set the content view, such as a TextView. The app is run by clicking Run > Run from Eclipse. Layouts define an app's UI using XML declarations of views and view groups. The XML layout is loaded in onCreate using setContentView.

Uploaded by

deep007_mm
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views

Android Document: How To Create A New Project?

To create a new Android project, open Eclipse, go to File > New > Android Project, enter a project name and select build options. An Android app contains an Activity class that extends Activity and overrides onCreate to set the content view, such as a TextView. The app is run by clicking Run > Run from Eclipse. Layouts define an app's UI using XML declarations of views and view groups. The XML layout is loaded in onCreate using setContentView.

Uploaded by

deep007_mm
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 4

Android Document

How to create a new project?

Follows the following steps to create a new project in Android:


1. Open eclipse.
2. File → New → Android Project. You will get the following window.

Enter the project name.


Select “Create new project in work space”
Select the build target.
Enter “Application Name”, “Package Name”, “Create Activity” and “Min SDK
Version”.
Then click on the Finish Button.
A hello android program

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class Hello 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, Learning Android is a great fun.");
setContentView(tv);
}
}

public class Hello extends Activity {

int the above line we are extending the Hello class from Activity class. An Activity is the place
where a user can add the view.

Public void onCreate(...) is a call back function that must be overridden by the derived class of
class Activity.
TextView tv = new TextView(this);
tv.setText("Hello Android, Learning Android is a great fun.");
setContentView(tv);

In the above three lines, we are creating an object of TextView and set the text “Hello Android,
Learning Android is a great fun.” to the TextView. And in the last line we are setting the
Content View as a TextView.

How to run the Android Application?


From the eclipse menu, click the Run → Run. This results the following screen.

Declaring Layout
Your layout is the architecture for the user interface in an Activity. It defines the layout
structure and holds all the elements that appear to the user. You can declare your layout in two
ways:

1. Declare UI elements in XML. Android provides a straightforward XML vocabulary


that corresponds to the View classes and subclasses, such as those for widgets and layouts.
2. Instantiate layout elements at runtime. Your application can create View and
ViewGroup objects (and manipulate their properties) programmatically.

Write the XML

We can quickly design the layout using Android XML files:


For example, here is an XML layout that uses a vartical LinearLayout to hold a TextView and a
Button.

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


<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, I am a TextView" />
<Button android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, I am a Button" />
</LinearLayout>

Load the XML Resource

You should load the layout resource from your application code, in your activity.onCreate()
callback implementation.

public void onCreate(Bundle savedInstanceState) {


super.onCreate(savedInstanceState);
setContentView.(R.layout.main_layout);
}

You might also like