Android Tutorials
Working With Android Contacts
Accessing Data With Android Cursors
Creating Lists Using The Android ListActivity
Android 9 Patch Scaled PNG Image Guide
Working With Images In Android
Exploring Android LinearLayout And RelativeLayout
Writing A Basic Android Application
Installing The Android SDK In Eclipse

Writing A Basic Android Application

Launching the RelativeLayout

The third button actually launches a new view. This is done with an on-click listener as before, but this time we launch a new view.

Button btnRelative = (Button) findViewById(;
btnRelative.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {
        Intent i = new Intent(TestApp.this, Relative.class);

Just as with the previous buttons we need to get the button and create an object with it. Then create an OnClickListener. This time the listener starts a new intent passing the current Class.this followed by the activity to launch. In this case Relative.class is the parameter. Then call startActivity passing the new intent to launch the activity. Finally call finish to complete the activity.

Now lets look at the file that contains the new activity. This activity simply displays the view from relative.xml. This is a simple Activity that just overrides the onCreate function. All we do is have to call the setContentView to the relative layout by passing the ID to the layout stored in the auto-generated R variable.

package com.higherpass.testapp;

import android.os.Bundle;

public class Relative extends Activity {
    public void onCreate(Bundle savedInstanceState) {

This wraps up writing a basic Android application and should get you started developing on your own.

Building The Android Code <<  1 2 3 4 5
New Content