Android project page Jump small Demo

Source: Internet
Author: User

Recently in the development of Android projects, just contact there will be a lot of new things to learn, from the environment to the language of the building to the familiarity of the need to step by step, and then take a page to jump sample to share with you about their experience.

The architecture used:

The Src/res/manifest file schema is used in the demo. Because I am a novice. It was done in accordance with this traditional architecture.

watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvdtaxmduwodgyng==/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/southeast ">

Overall structure:

In the project, the main need to write their own Java class in the src file, the res layout file to write their own page of the XML file, as well as the completion of the Mainifest Java class configuration.

watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvdtaxmduwodgyng==/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/southeast ">

This example enables you to jump to the second page when you click the button on the Helloword page, such as the following:

Before jump

After jump

First we need to build two Java classes: Mainactivity & secondactivity, code such as the following:

"Mainactivity"

<span style= "FONT-FAMILY:KAITI_GB2312;FONT-SIZE:18PX;" >package Com.example;import Android. R.color;import Android.os.bundle;import Android.app.activity;import Android.content.intent;import Android.graphics.color;import Android.graphics.pdf.pdfdocument;import Android.view.menu;import Android.view.View; Import Android.view.view.onclicklistener;import Android.widget.button;import Android.widget.textview;public class    Mainactivity extends Activity {//define your own private Button Btnbutton;        @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);        Setcontentview (R.layout.activity_main);        Btnbutton = (Button) Findviewbyid (R.id.button1);        Btnbutton.setwidth (200);        Btnbutton.setheight (50);                Btnbutton.setbackgroundcolor (color.red); Btnbutton.setonclicklistener (New Onclicklistener () {@Overridepublic void OnClick (View v) {//TODO auto-generated method Stubintent Intent = new Intent (); Intent.setclass (MainACtivity.this, Secondactivity.class); startactivity (intent);}); } @Override Public boolean Oncreateoptionsmenu (Menu menu) {//Inflate the menu, this adds items to the Actio        n Bar if it is present.        Getmenuinflater (). Inflate (R.menu.main, menu);    return true; }}</span>

"Secondactivity"

<span style= "FONT-FAMILY:KAITI_GB2312;FONT-SIZE:18PX;" >package com.example;import Android.app.activity;import Android.os.bundle;public class SecondActivity extends activity{protected void OnCreate (Bundle savedinstancestate) {        super.oncreate (savedinstancestate);        Setcontentview (R.layout.activity_second);        }} </span>

At the same time, the XML file is created accordingly in the layout directory. To complete the design of the page,

"Activity_main"

<span style= "FONT-FAMILY:KAITI_GB2312;FONT-SIZE:18PX;" ><relativelayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http// Schemas.android.com/tools "android:layout_width=" match_parent "android:layout_height=" Match_parent "Android:paddi ngbottom= "@dimen/activity_vertical_margin" android:paddingleft= "@dimen/activity_horizontal_margin" Android: paddingright= "@dimen/activity_horizontal_margin" android:paddingtop= "@dimen/activity_vertical_margin" tools: Context= ". Mainactivity "> <textview android:id=" @+id/textview1 "android:layout_width=" Wrap_content "an droid:layout_height= "Wrap_content" android:text= "@string/hello_world"/> <button android:id= "@+id/b Utton1 "android:layout_width=" wrap_content "android:layout_height=" Wrap_content "Android:layout_below       = "@+id/textview1" android:layout_margintop= "119DP" android:layout_torightof= "@+id/textview1" android:text= "button"/></relativelayout></span> 

"Activity_second"

<span style= "FONT-FAMILY:KAITI_GB2312;FONT-SIZE:18PX;" ><?

XML version= "1.0" encoding= "Utf-8"?

><linearlayout xmlns:android= "http://schemas.android.com/apk/res/android" android:layout_width= "match _parent " android:layout_height=" match_parent " android:orientation=" vertical "> <textview Android:id= "@+id/textview1" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" android:text= "Second"/></linearlayout></span>

Next we need to complete the configuration of the two Java classes created in the Manifestfile file:

<span style= "FONT-FAMILY:KAITI_GB2312;FONT-SIZE:18PX;" ><?xml version= "1.0" encoding= "Utf-8"? ><manifest xmlns:android= "http://schemas.android.com/apk/res/ Android "package=" Com.example "android:versioncode=" 1 "android:versionname=" 1.0 "> <uses-sdk Android        oid:minsdkversion= "android:targetsdkversion="/> <application android:allowbackup= "true" android:icon= "@drawable/ic_launcher" android:label= "@string/app_name" android:theme= "@style/apptheme" &G        T            <activity android:name= "com.example.MainActivity" android:label= "@string/app_name" > <intent-filter> <action android:name= "Android.intent.action.MAIN"/> <categ                Ory android:name= "Android.intent.category.LAUNCHER"/> </intent-filter> </activity> <activity android:name= "Com.example.SecondActivity" andRoid:label= "@string/app_name" > <intent-filter> </intent-filter> </activi Ty> </application></manifest></span>


It is necessary to emphasize that each Java class is added. All need to complete the corresponding configuration in the Androidmanifest!

Such a simple Android mini-demo will be formed. Examples are very easy, and many others are familiar with the development environment. I hope to be able to have just contact with Android development friends have some help, there are problems can always contact me.

Android project page Jump small Demo

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.