Android first line code-1. Project structure

Source: Internet
Author: User

0. Project structure

A simple Android project structure is roughly as follows

The entrance is mainactivity this class, if for an unfamiliar project, the best way is to see Androidmainifest.xml, as follows

<?XML version= "1.0" encoding= "Utf-8"?><Manifestxmlns:android= "Http://schemas.android.com/apk/res/android" Package= "Activitytest.example.com.firstactivity">    <ApplicationAndroid:allowbackup= "true"Android:icon= "@mipmap/ic_launcher"Android:label= "@string/app_name"Android:supportsrtl= "true"Android:theme= "@style/apptheme">        <ActivityAndroid:name=". Mainactivity "Android:label= "@string/app_name"Android:theme= "@style/apptheme.noactionbar">            <Intent-filter>                <ActionAndroid:name= "Android.intent.action.MAIN" />                <categoryAndroid:name= "Android.intent.category.LAUNCHER" />            </Intent-filter>        </Activity>    </Application></Manifest>

You can see that Android:name is. Mainactivity, from Androidmainifest.xml can see that the project has only one activity, the entrance of the activity is mainactivity.

1. Project structure

Through activity, it is easy to find the corresponding project structure.

@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Requestwindowfeature (Window.feature_no_title);        Setcontentview (R.layout.activity_main); FinalButton Button =(Button) Findviewbyid (r.id.button_1); FinalButton Button_finish =(Button) Findviewbyid (r.id.button_finish); Button.setonclicklistener (NewView.onclicklistener () {@Override Public voidOnClick (View v) {toast.maketext (mainactivity. This, "You touch This button", Toast.length_long). Show ();        }        }); Button_finish.setonclicklistener (NewView.onclicklistener () {@Override Public voidOnClick (View v) {finish (); }        });

Enter Mainactivity, find the OnCreate method, which is the first method that the activity calls, Setcontentview (R.layout.activity_main) can load a layout for the activity, The reference to static resources here is activity_main.xml, note that the R object, which can call the Res folder below the resources.

Activity_main.xml is the equivalent of V in MVC, let's see what it looks like.

<LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:orientation= "vertical" >    <ButtonAndroid:id= "@+id/button_1"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:text= "Alex"        />    <ButtonAndroid:id= "@+id/button_finish"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:text= "Finish"/></LinearLayout>

With the components you add yourself, you can display them in the layout of your activity.

Android first line code-1. Project structure

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.