Package Com.paad.helloworld;import Android.os.bundle;public class MyActivity extends activity{@Override public voi D onCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.main); }}
Activity is the base class for interactive components that are visible in the application, which is roughly equivalent to a form in a traditional desktop application development. In the example above, it expands the activity and overrides the OnCreate method.
In Android, visual components, called views, are similar to controls in traditional desktop application development. Because Setcontentview can lay out the user interface by extending a layout resource, we override the OnCreate method and use it to invoke Setcontentview.
The resources for Android projects are stored in the Res folder of the project hierarchy, which contains Layout,values and a series of drawable subfolders. The ADT plug-in interprets these resources and provides design-time access to them through R variables.
The following code defines the UI layout that is created by the Android project template and stored in the project's Res/layout folder:
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "android:orientation=" vertical "android:layout_width=" fill_parent "android:layout_height=" Fill_parent " ; <textview android:layout_width= "fill_parent" android:layout_height= "wrap_content" android:text= "@string/h Ello "/></linearlayout>
Hello World, the first Android program