Use Android to click the button to jump page

Source: Internet
Author: User

1. First create a new Android project, named MyApp (the name can be arbitrarily up);

2. Use the original Mainactivity.java file as the login interface, then right-click on the package in the SRC file to select Android activity in other under the new directory, select Blankactivity, modify the name of an activity ( Custom), I named Bankactivity here, click Finish and then create a new return page;

3. Next, we will add the layout file, in the res file in the layout file first double-click Activity_main.xml, on the Android page, drag a button, double-click it, the Android:id= "@+id/btn1" in the "@+id/" Change the name of the following to BTN1, and then android:text the text in double quotation marks to log in, the same way, the name in the Activity_bank.xml file is modified as described above;

4. Open the Mainactivity.java file, write the following code, and remember to write the code in the OnCreate Method!

1  PackageCom.example.myapp;2 3 ImportAndroid.os.Bundle;4 Importandroid.app.Activity;5 Importandroid.content.Intent;6 ImportAndroid.view.Menu;7 ImportAndroid.view.View;8 ImportAndroid.view.View.OnClickListener;9 ImportAndroid.widget.Button;Ten  One  Public classMainactivityextendsActivity { A  - @Override -     protected voidonCreate (Bundle savedinstancestate) { the         Super. OnCreate (savedinstancestate); - Setcontentview (r.layout.activity_main); -          -         //The control of the view layer and the control of the business layer are associated by ID and mapped to the BTN1 assignment, that is, setting the button ID in the layout file +Button btn1=(Button) Findviewbyid (R.ID.BTN1); -          +         //binding listener events to BTN1 ABtn1.setonclicklistener (NewOnclicklistener () { at              - @Override -              Public voidOnClick (View v) { -                  -                 //Add a Click response event to Bnt1 -Intent Intent =NewIntent (mainactivity. This, Bankactivity.class); in                 //Start - startactivity (intent); to             } +         }); -          the     } *  $ @OverridePanax Notoginseng      Public BooleanOncreateoptionsmenu (Menu menu) { -         //inflate the menu; This adds items to the action bar if it is present. the getmenuinflater (). Inflate (R.menu.activity_main, menu); +         return true; A     } the      +}

Remember to add it on the class: import android.content.Intent;

5. Point open the Bankactivity.java file: write the following code:

1  PackageCom.example.myapp;2 3 ImportAndroid.os.Bundle;4 Importandroid.app.Activity;5 ImportAndroid.view.Menu;6 ImportAndroid.view.View;7 ImportAndroid.view.View.OnClickListener;8 ImportAndroid.widget.Button;9 Ten  Public classBankactivityextendsActivity { One  A @Override -     protected voidonCreate (Bundle savedinstancestate) { -         Super. OnCreate (savedinstancestate); the Setcontentview (R.layout.activity_bank); -          -Button btn2=(Button) Findviewbyid (R.ID.BTN2); -Btn2.setonclicklistener (NewOnclicklistener () { +              - @Override +              Public voidOnClick (View v) { A                 //TODO auto-generated Method Stub at finish (); -             } -         }); -     } -  - @Override in      Public BooleanOncreateoptionsmenu (Menu menu) { -         //inflate the menu; This adds items to the action bar if it is present. to getmenuinflater (). Inflate (R.menu.activity_bank, menu); +         return true; -     } the  *}

Then save right click on the MyApp executable file, you can implement click Button Jump Page!

The realization of this small function is not difficult, in the future learning life encountered difficulties do not panic, do not be afraid, to actively take the strategy to solve the problem, troubleshooting, must have confidence, in the face of success, all the difficulties are paper tigers, encounter problems, multi-brain, diligent thinking, more hands-on, always solve the problem.

All there is nothing!   Nothing is difficult, I am afraid of a conscientious. Small friends, we refuel together!!!

Use Android to click the button to jump page

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.