0% found this document useful (0 votes)
44 views

Mobile Application Development Lab-1

The document provides instructions for developing a basic mobile calculator application in Android. It involves: 1. Creating a new Android project in Eclipse and designing a simple user interface with two edit texts for input, a button, and a text view to display the output. 2. Adding code to the MainActivity class to retrieve the input values, perform addition, and update the output text view when the button is clicked. 3. Configuring and running an Android Virtual Device to test the application.
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views

Mobile Application Development Lab-1

The document provides instructions for developing a basic mobile calculator application in Android. It involves: 1. Creating a new Android project in Eclipse and designing a simple user interface with two edit texts for input, a button, and a text view to display the output. 2. Adding code to the MainActivity class to retrieve the input values, perform addition, and update the output text view when the button is clicked. 3. Configuring and running an Android Virtual Device to test the application.
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 8

Mobile Application Development

Lab-1
1. Run a Hello World program first.
2. Write a program to add two numbers. (Hint: you can follow the below steps)
3 .After completion of Q1 and Q2 ,design a calculator for arithmetic operations.
--------------------------------------------------------------------------------------------------1. run eclipse
2. Create a new project:
File -> new-> android application project

Click Next

Click Next
Click Next

Click Next

Click Finish.

Now see that a new application has been created as SumApp(check in R.H.S).
there are 2 files also:
SumApp->src->com.sumapp-> MainActivity.java (this contains source code)
SumApp->res->layout-> activity_main.xml (this contains design screen)

3. Open activity_main.xml from L.H.S by double clicking it, switch to tab:"Graphical Layout"
to design the screen as follows:

Figure 1
To draw various elements(drag from Palette):

4. change the IDs of each element drawn on screen as shown in R.H.S of Figure 1.
example: editTextN1, editTextN2,buttonSum,textViewS.
How to change ID of an element:
right click on an element-> select "Edit ID..."

5. Code the application logic in MainActivity.java file.(Green means <autogenerated code>)


(Rest is additional code).
So this file should appear as follows:
MainActivity.java
package com.sumapp;
import
import
import
import
import
import
import
import

android.os.Bundle;
android.app.Activity;
android.view.Menu;
android.view.View;
android.view.View.OnClickListener;
android.widget.Button;
android.widget.EditText;
android.widget.TextView;

public class MainActivity extends Activity

{
EditText e1;
EditText e2;
Button b;
TextView t;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
e1= (EditText) findViewById(R.id.editTextN1);
e2= (EditText) findViewById(R.id.editTextN2);
b= (Button) findViewById(R.id.buttonSum);
t= (TextView) findViewById(R.id.textViewS);
b.setOnClickListener(new OnClick());
}
public class OnClick implements OnClickListener
{
@Override
public void onClick(View v)
{
int n1;
n1= Integer.parseInt( e1.getText().toString());
int n2= Integer.parseInt( e2.getText().toString());
int sum=n1+n2;
t.setText(Integer.toString(sum));
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}

6. Save your application.


File-> Save All.

7. Create an AVD(Android Virtual device) to test your application.


Window(menu at top) -> Android Virtual device manager
click on "New" button
create as follows:

Now it displays as follows:

Click on "Start" button

click on "Launch" button.


Now it displays as:

8. Run your application on AVD created above:

9. Now you can play with newly created application.

You might also like