Android Development making face switch tutorial

Source: Internet
Author: User
Tags xmlns

Software platform: Windows 7 + Eclipse + SDK

Design ideas:

Two pages: Mian and OK, there is a button on each page, click can switch to each other

Source:

Main.xml Source code:

The code is as follows Copy Code
XML version= "1.0" encoding= "Utf-8"?>
<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"
android:orientation= "Vertical"
Android:layout_width= "Fill_parent"
android:layout_height= "Fill_parent"
>
<textview
Android:layout_width= "Fill_parent"
android:layout_height= "Wrap_content"
android:text= "@string/hello"
/>
<button android:id= "@+id/button1" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" android:text= "Next Page" >Button>
Linearlayout>

Ok.xml Source code:

The code is as follows Copy Code

XML version= "1.0" encoding= "Utf-8"?>
<linearlayout
Xmlns:android= "Http://schemas.android.com/apk/res/android"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent" >
<button android:layout_width= "wrap_content" android:layout_height= "Wrap_content" android:text= "Previous page" Android:id = "@+id/button1" >Button>
Linearlayout>

Makechoice Source code:

Package com.makechoice;

Import Android.app.Activity;
Import Android.os.Bundle;
Import Android.view.View;
Import Android.widget.Button;

public class Makechoice extends activity
{
/** called the activity is a. */
@Override
public void OnCreate (Bundle savedinstancestate)
{
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);
Button btn = (button) Findviewbyid (R.id.button1);
Btn.setonclicklistener (New Button.onclicklistener ()
{
@Override
public void OnClick (View v)
{
Jump2ok ();
}
});
}

Skip to OK page
public void Jump2ok ()
{
Setcontentview (R.layout.ok);
When a button is pressed to jump to main page
Button btn = (button) Findviewbyid (R.id.button1);
Btn.setonclicklistener (New Button.onclicklistener ()
{
@Override
public void OnClick (View v)
{
Jump2main ();
}
});
}

Skip to Main Page
public void Jump2main ()
{
Setcontentview (R.layout.main);
When a button is pressed to jump to the OK page
Button btn = (button) Findviewbyid (R.id.button1);
Btn.setonclicklistener (New Button.onclicklistener ()
{
@Override
public void OnClick (View v)
{
Jump2ok ();
}
});
}
}

Run Effect chart:

Attention:

The ID number stored in class R is the ID number of the current page, so the control that the Findviewbyid function captures is also the control of the current page

Related Article

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.