[Android] 1, page jump + button monitoring

Source: Internet
Author: User

A total of 2 layout:main.xml and Other.xml;2 Activity:mainactivity.java,otheractivity.java

Rewrite OnCreate in mainactivity, line 6th set Button Listen ~

1  Public voidonCreate (Bundle savedinstancestate) {2     Super. OnCreate (savedinstancestate);3 Setcontentview (r.layout.main);4LOG.V ("Mainactivity", "OnCreate");5BTN =(Button) Findviewbyid (R.ID.MAIN_BTN);6Btn.setonclicklistener ( This);7     //this.finish ();//End Current Mainactivity8}

Here is the implementation of the button listener: that is, when the button is pressed, jump to another page:

1 @Override2  Public voidOnClick (View arg0) {3     if(arg0 = =btn) {4Intent Intent =NewIntent ();5Intent.setclass ( This, Otheractivity.class);6          This. StartActivity (intent);7     }8}

Another activity is similar:

 1  public  void       OnCreate (Bundle savedinstancestate) { 2  super  .oncreate (savedinstancestate);  3   Setcontentview (r.layout.other);  4  log.v ("mainactivity", "OnCreate"  5  btn =6  Btn.setonclicklistener (this  " Span style= "color: #000000;" >); 7 } 
1  Public void OnClick (View arg0) {2     if (arg0 = = btn) {3          This . Finish (); 4     }5 }

Some people will think otheractivity why that look, for the moment I do not know, first put his XML file:

1 <?XML version= "1.0" encoding= "Utf-8"?>2 <LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"3 android:orientation= "vertical"4 Android:layout_width= "Fill_parent"5 Android:layout_height= "Fill_parent"6     >7 <TextView8     Android:layout_width= "Fill_parent" 9 Android:layout_height= "Wrap_content" Ten Android:text= "@string/otheractiviy_hello" One     /> A <Button -     Android:layout_width= "Fill_parent"  - Android:layout_height= "Wrap_content"  the Android:text= "@string/otheractiviy_btnclose" - Android:id= "@+id/other_btn" -     /> - </LinearLayout>

This article link: http://www.cnblogs.com/zjutlitao/p/4229540.html

More Highlights: http://www.cnblogs.com/zjutlitao/

[Android] 1, page jump + button monitoring

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.