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 familiar is a step-by-step, and then take a page to jump to the example to share with you some of their experience.

The architecture used:

The demo uses the Src/res/manifest file architecture, and as a novice, it follows this traditional architecture.

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 mainifest to complete the Java class configuration.

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

Before jump

After jump

First of all we need to build two Java classes: Mainactivity & Secondactivity, the code is as follows:

"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 in the Layout folder to create an XML file 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:o rientation= "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 established 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 should be emphasized that every Java class is added, and the corresponding configuration must be done in Androidmanifest!

Such a simple Android small demo on the form, the example is very simple, more familiar with the development environment and understanding, I hope to have just contact with Android development friends have some help, there are problems can also contact me at any time!

Android project page Jump small Demo

Related Article

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.