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->[Link]-> [Link] (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 [Link] file.(Green means <autogenerated code>)
(Rest is additional code).
So this file should appear as follows:
[Link]
package [Link];
import
import
import
import
import
import
import
import
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
public class MainActivity extends Activity
{
EditText e1;
EditText e2;
Button b;
TextView t;
@Override
protected void onCreate(Bundle savedInstanceState)
{
[Link](savedInstanceState);
setContentView([Link].activity_main);
e1= (EditText) findViewById([Link].editTextN1);
e2= (EditText) findViewById([Link].editTextN2);
b= (Button) findViewById([Link]);
t= (TextView) findViewById([Link]);
[Link](new OnClick());
}
public class OnClick implements OnClickListener
{
@Override
public void onClick(View v)
{
int n1;
n1= [Link]( [Link]().toString());
int n2= [Link]( [Link]().toString());
int sum=n1+n2;
[Link]([Link](sum));
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate([Link], 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.