1. A jump between two. xml files:
Achieve the effect: when the button is clicked, you can jump to another page
A. Method One: Use the Setcontentview () method with the function call to implement:
public class Mainactivity extends Appcompatactivity {
Private Button bt1;
Private Button BT2;
@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);
bt1= (Button) Findviewbyid (R.id.button1);
Bt1.setonclicklistener (New View.onclicklistener () {
@Override
public void OnClick (View v) {
JumpToLayout2 ();
}
});
}
public void JumpToLayout2 () {
Setcontentview (r.layout.mylayout);
Bt2= (Button) Findviewbyid (R.id.button2);
Bt2.setonclicklistener (New View.onclicklistener () {
@Override
public void OnClick (View v) {
JUMPTOLAYOUT1 ();
}
});
}
public void JumpToLayout1 () {
Setcontentview (r.layout.activity_main);
bt1= (Button) Findviewbyid (R.id.button1);
Bt1.setonclicklistener (New View.onclicklistener () {
@Override
public void OnClick (View v) {
JumpToLayout2 ();
}
});
}
}
B. Method two: Through an activity binding an XML file, and then implement the activity of the jump to achieve the two XML file jump:
It is important to note that because there are two activity to be used here, it is important to declare in mainfest that the newly created activity:
<activity android:name= ". Mainactivity "
<intent-filter>
<action android:name=" Android.intent.action.MAIN "/> ;
<category android:name= "Android.intent.category.LAUNCHER"/>
</intent-filter>
</a Ctivity>
<activity android:name= ". Mylayout";
< Intent-filter>
<action android:name= "Android.intent.action.MAIN"/>
<category Androi D:name= "Android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
And then through the intent way to achieve the jump:
for mainactivity page:
public class Mainactivity extends Appcompatactivity {
private Button bt;
@Override
protected void onCreate (final Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
//Bind layout file Activity_main.xml file
setcontentview (R.layout.activity_main);
bt= (Button) Findviewbyid (r.id.button1);
Bt.setonclicklistener (New View.onclicklistener () {
@Override
public void OnClick (View v) {//For the following two parameters, respectively, represents this page and the parameters of the jump page, but note that this page is used this, to jump to the page is the class
inte NT Intent=new Intent (Mainactivity.this,mylayout.class);
startactivity (intent);
}
});
}
}
for mylayout page:
public class Mylayout extends Activity {
Private Button BT;
@Override
protected void OnCreate (final Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Binding mylayout.xml Files
Setcontentview (r.layout.mylayout);
bt= (Button) Findviewbyid (R.id.button2);
Bt.setonclicklistener (New View.onclicklistener () {
@Override
public void OnClick (View v) {
Intent intent=new Intent (mylayout.this,mainactivity.class);
StartActivity (Intent);
}
});
}
}
Android's implementation layout jump