Android OneDayOneExample-1. Page swapping

Source: Internet
Author: User
Package COM. example. tuo; import android. app. activity; import android. content. intent; import android. OS. bundle; import android. view. menu; import android. view. view; import android. widget. button; import android. widget. edittext; import android. widget. textview; public class mainactivity extends activity {protected static final string getnameedittext = NULL; private textview long; private edittext edit; @ overridepro Tected void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. activity_main);/* findviewbyid (R. id. button1) Get the layout main. button1 */button button1 = (button) findviewbyid (R. id. button1); long = (textview) findviewbyid (R. id. textview1); Edit = (edittext) findviewbyid (R. id. edittext1); Edit. settext ("Hello! ");/* Listen to button event information */button1.setonclicklistener (New button. onclicklistener () {public void onclick (view v) {/* Create an intent object */intent = new intent ();/* specify the intent class */intent. setclass (mainactivity. this, activity02.class);/* start a new activity */startactivity (intent);/* close the current activity */mainactivity. this. finish (); long. settext ("thesend") ;}}); button button4 = (button) findviewbyid (R. id. button_close);/* listen to button event information */button4.setonclicklistener (New button. onclicklistener () {public void onclick (view v) {mainactivity. this. finish () ;}}) ;}@ overridepublic Boolean oncreateoptionsmenu (menu) {// inflate the menu; this adds items to the action bar if it is present. getmenuinflater (). inflate (R. menu. activity_main, menu); Return true ;}}
Package COM. example. tuo; import android. app. activity; import android. content. intent; import android. OS. bundle; import android. view. view; import android. widget. button; import android. widget. textview; public class activity02 extends activity {private textview long2; @ overrideprotected void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate);/* set to display main2.xml Layout */setcontentview (R. layout. main2);/* findviewbyid (R. id. button2) Get the layout main. button2 */button = (button) findviewbyid (R. id. button1); // edit = (edittext) findviewbyid (R. id. edit); long2 = (textview) findviewbyid (R. id. textview1);/* Listen to the event information of the button */button. setonclicklistener (New button. onclicklistener () {public void onclick (view v) {/* Create an intent object */intent = new intent ();/* specify the intent class */intent. setclass (activity02.this, mainactivity. class);/* start a new activity */startactivity (intent);/* close the current activity */activity02.this. finish (); long2.settext ("first page ");}});}}

After adding a new activity, remember to register it in androidmainfest. xml.

<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"      package="com.yarin.android.Examples_03_02"      android:versionCode="1"      android:versionName="1.0">    <uses-permission android:name="android.permission.READ_CONTACTS"></uses-permission>    <application android:icon="@drawable/icon" android:label="@string/app_name">        <activity android:name=".Activity01"                  android:label="@string/app_name">            <intent-filter>                <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER" />            </intent-filter>        </activity>    </application>    <uses-sdk android:minSdkVersion="9" /></manifest> 

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.