Every time we use Hello World to learn our first work,I name it “Hello Activity”, since the most different term comparing with iOS, the android prefers to “Activity”.
I borrowed a Tutorial Book of Android yesterday in Library. There is a good note introducing the difference between the application and activity.
“an application can be composed of multiple activities, but one application must have at least one activity”.So Today my work is to create an application of Android with one activity.
1. Create an Android Project in Eclipse
Maybe different Eclipse versions are different, this figure shows there is no android project in the New menu, but I found it after clicking Other…
Choose the Android Application Project, set the project name and other settings, then a wizard will be created in your workspace.
2.See the structure of the Project
It is helpful to look at the structure of the project, because it can tell us how the android project manage the source and resource. When we develop the real project,we can organize it depends on the requirement of the design or other team members.
What I am focusing on is
a)FirstActivity.java, which I could implement by adding the UI elements.
b)activity_first.xml, which is a layout file of FirstActivity class, the content is based on the rule of XML, so you should have some conceptions about it.
c)R.java, which is generated automatically, so never modify this file directly.
3.Add a simple widget in the HelloActivity
when I created the project with blank activity, a TextView was auto-generated. So I removed it!
And then create one in the override method named onCreate in FirstActivity.java.
1:TextView HelloTextView= new TextView(this);
2:HelloTextView.setText(“Hello My First TextView”);
4.Run the application on emulator
OK, after that, we can run the application to see what will happen.
Easy, right! Have Fun~