Java-android page jump and structure construction

Source: Internet
Author: User

Every page in Android is an activity, it is important to make these pages jump, it is the simplest

First, there is a main page main.xml

<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/    Android "Android:layout_width=" Fill_parent "android:layout_height=" fill_parent "android:orientation=" vertical " android:background= "@drawable/bg" > <textview android:layout_width= "fill_parent" android:layou        t_height= "Wrap_content" android:text= "@string/hello"/> <tablerow android:id= "@+id/tablerow1"         Android:layout_width= "Match_parent" android:layout_height= "wrap_content" android:layout_weight= "0.31" > <button android:id= "@+id/button1" android:layout_width= "Wrap_content" Android:             layout_height= "Wrap_content" android:text= "@string/musicbutton" android:onclick= "opmusicactivity"            /> <button android:id= "@+id/button2" android:layout_width= "Wrap_content" Android:layout_height= "Wrap_Content "android:text=" @string/textbutton "android:onclick=" optextactivity "/> <button android:id= "@+id/button3" android:layout_width= "Wrap_content" Android:layout_                height= "Wrap_content" android:text= "@string/vediobutton" android:onclick= "opvedioactivity" /> </TableRow></LinearLayout>

This page has three buttons, each button has a corresponding registration event, is to trigger the button event, to achieve jump events, jump to a single page, too simple to list out the code, their own design

Main method: Mainactivity.java write the corresponding event of the button, when the event occurs, it will call the corresponding method, each method has a method to activate the component

package Com.szy.test;import Android.app.activity;import    Android.content.intent;import Android.os.bundle;import Android.view.view;public class MainActivity extends Activity { /** called when the activity is first created.        */@Override public void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);    Setcontentview (R.layout.main);    } public void Opmusicactivity (View v) {//TAP music Intent Intent = new Intent ();    Intent.setclassname (This, "com.szy.test.MusicActivity");    StartActivity (Intent);    } public void Optextactivity (View v) {//click text Intent Intent = new Intent ();    Intent.setclassname (This, "com.szy.test.TextActivity");        StartActivity (Intent);    } public void Opvedioactivity (View v) {//click on video Intent Intent = new Intent ();    Intent.setclassname (This, "com.szy.test.VedioActivity");    StartActivity (Intent); }}

Musicactivity.java component, which displays a page

Package Com.szy.test;import Android.app.activity;import Android.os.bundle;public class Musicactivity extends Activity {Public    void OnCreate (Bundle savedinstancestate) {        super.oncreate (savedinstancestate);        Setcontentview (R.layout.music);    }}

Finally, the activity is registered in Androidmanifest.xml:

<?xml version= "1.0" encoding= "Utf-8"? ><manifest xmlns:android= "http://schemas.android.com/apk/res/ Android "package=" Com.szy.test "android:versioncode=" 1 "android:versionname=" 1.0 "> <uses-sdk android:mi nsdkversion= "8"/> <application android:icon= "@drawable/ic_launcher" android:label= "@string/app_nam E "> <activity android:label=" @string/app_name "Android:name=". Mainactivity "> <intent-filter > <action android:name=" Android.intent.action.MAIN "/        > <category android:name= "Android.intent.category.LAUNCHER"/> </intent-filter> </activity> <activity android:label= "@string/music" Android:name= ". Musicactivity "> </activity> <activity Andro Id:label= "@string/text" Android:name= ".            Textactivity "></activity> <activity android:label= "@string/vedio" android:name= ". Vedioactivity "> </activity> </application></manifest&gt ;

This is enough to achieve the Click button implementation of the page jump------

Java-android page jump and structure construction

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.