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?