How do I bind an Android Click Event-Jump to another page and implement the close function?

Source: Internet
Author: User

One, click the button to jump to another page.

Eg: implementation from one page click to jump to another page

1, first in a layout file (. XML), a jump button (ID btn1) was painted:

<button
Android:id= "@+id/btn1"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:text= "Click to jump"/>

2. Then declare a private button name in the associated class, such as:

Private Button btn1;

TIPS: Added on the class: import Android.widget.Button;

3. Then do the following within the OnCreate method in the class:

(1), assign a value to BTN1, that is, set the button ID of the layout file to associate, such as:

BTN1 = (Button) Findviewbyid (R.ID.BTN1);

(2), to BTN1 binding fixed-point hit event:

Btn1.setonclicklistener (New View.onclicklistener () {
@Override
public void OnClick (View v) {
}
});

TIPS: Added on the class: import Android.view.View;

(3), add click Response Events to Bnt1:

Btn1.setonclicklistener (New View.onclicklistener () {
@Override
public void OnClick (View v) {

Intent is a runtime binding (Run-time binding) mechanism that connects two different components during a program's run.

Page1 is the previously added class, and the active event is added within Androidmanifest.xml (<activity android:name= "Page1" ></activity>), Under the folder where the resource code is stored,
Intent i = new Intent (mainactivity.this, Page1.class);

Start
StartActivity (i);
}
});

TIPS: Added on the class: import android.content.Intent;

4, finally, you can jump to the next page.

Second, the realization of the page closed

1. First add a button within the page1.xml that has been associated with the class Page.java, such as:

(TIPS: How to Page association see: http://www.cnblogs.com/waitingbar/p/4409000.html)

<button
Android:id= "@+id/btnclose"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:text= "Click to close"/>

2. Then bind the button event to the same as the jump page, such as:

class to add the declaration: private Button Btnclose;

To add a binding event:

Btnclose = (Button) Findviewbyid (r.id.btnclose);
Btnclose.setonclicklistener (New View.onclicklistener () {
@Override
public void OnClick (View v) {
Finish ();
}
});

Tips:finish () is the closing method for click event Response

3. Finally, it's done ... Please click to download the following source code: source Download

How do I bind an Android Click Event-Jump to another page and implement the close function?

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.