After setting up Android working environment we will start designing our own sample application, which we will test using Robotium in next section.
Our sample application would be a simple calculator to multiply two integer/decimal values. It will take two inputs and on clicking ‘Multiply’ it will show their multiply result.
For simplicity steps are categorized as,
1. Create Project
Click on File menu, select New and click on the Others, from New window, Drag down to Android option, expand it, and select Android Project and Click on Next.
From New Android Project Window, enter Project Name as ‘AndroidCalculator’, From Contents section select ‘Create New Project in workspace’, Check Android 2.2 from Build Target section, Application Name ‘AndroidCalculator’, Package Name ‘com.calculator’, Create Activity ‘Main’ and ‘8’ as Min SDK Version
Note: you can enter any other options best suits to your need.
Click on Next and it will load New Android Project window eclipse offer you to create project to test your project, at this time we will avail it to test ‘AndroidCalculator’ we made in last step. We can skip this part by un-checking Create a Test Project option, if you want to manually create test project later, we will create test project right away.
2. Create Test Project
Check Create a Test Project and it will automatically fill rest of fields based on the last made project (AndroidCalculator), and click on Finish.
Note: As our current focus is to design sample project so for now, we will just create test project and in next section we will be working on this new created project to test AndroidCalculator.
After successfully creating projects, our Project explorer screen should look like,
Now two projects are created, we will simply work on first project to design our sample calculator application.
3. Understand Project Architecture
Expand the src directory then expand com.calculator directory, Main.java file contains application logic. In rec directory we can define application’s UI interface. In Main.xml we can put controls on application interface and in string.xml we can define their string values,which would be visible on UI.
We would not get into details, as its not in our scope so far.
4. Design Layout
Get the code for main.xml and string.xml from Android Calculator Code
5. Design Application Logic
In Main.java enter following code and save it.Our application is designed and its time to run it.Right click on project select Run As and then select Android Application & and wait for while.It will load Android simulator, you need to wait for some time, it will launch application itself.
Our simple multiply calculator is ready, enter some integer/decimal values and click on Multiply, it will show the result above Click button.
Next: In next step we will work on AndroidCaculatorTest project to test that simple calculator. Download Android Calculator Code