Android UI Example


Hope you have already installed Android in your workstation. So you are ready to write some code. In this tutorial, we will be familiar with different Android UI elements. For this purpose we will create a “General Knowledge Test” app for our Android device. It can ask you some questions and show you the result. I hope you already know how to create a project with Eclipse ADT.

Before start we need to clear about some terms of Android. We will only discuss in short, what we will need to know for our tutorial.

Activity: An activity is a single class or you can say single user interface by which you can do a single task. To run on activity we have to have one Java class and a layout. If you have 5 activities, you will have 5 screen or window in your android device.

Intent: Intent is an abstract description of an operation to be performed. It can be used with startActivity. Intent provides a facility for performing late runtime binding between the code in different applications. Its most significant use is in the launching of activities, where it can be thought of as the glue between activities.

Activity Life Cycle: Activities in the system are managed as an activity stack. When a new activity is started, it is placed on the top of the stack and becomes the running activity — the previous activity always remains below it in the stack, and will not come to the foreground again until the new activity exits.

Step 1:

First create an Android project named AndroidUIActivity. Open res/values/strings.xml file.

Now, open the res/layout folder and create a new layout xml file called exam_ui.xml

Open, activity_android_ui.xml file from the same folder and add the missing code.

Step 2:
Open from the res/ folder and add the following code –

Now create a new class called inside the same package –

Step 3:
We have two activities in our app. We need to add it to our AndroidManifest.xml file –

We are all done. Right click on the project, click Run As > Android Application. The app will run on the emulator.

Leave A Reply

Your email address will not be published.