Activity to another Acivity

Source: Internet
Author: User

Res/main. xml

<? Xml version = "1.0" encoding = "UTF-8"?> <AbsoluteLayout xmlns: android = "http://schemas.android.com/apk/res/android" android: orientation = "vertical" android: layout_width = "fill_parent" android: layout_height = "fill_parent"> <Button android: id = "@ + id/btn1" android: layout_x = "118dip" android: text = "Button" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_y = "145dip"> </Button> <TextView android: text = "This is the first Activity" android: layout_width = "fill_parent" android: id = "@ + id/textView1" android: layout_height = "wrap_content" android: layout_x = "5dip" android: layout_y = "92dip"> </TextView> </AbsoluteLayout>

Res/ex03_09_01.xml

<? Xml version = "1.0" encoding = "UTF-8"?> <AbsoluteLayout xmlns: android = "http://schemas.android.com/apk/res/android" android: layout_width = "fill_parent" android: layout_height = "fill_parent"> <TextView android: text = "this is the second Activity" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_x = "122dip" android: layout_y = "96dip" android: id = "@ + id/tv2"> </TextView> <Button android: layout_x = "shortdip" android: text = "Button" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_y = "130dip" android: id = "@ + id/btn2"> </Button> </AbsoluteLayout>

Src/EX03_09.java

package gphone.ex03_09;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.view.View;import android.widget.Button;public class EX03_09 extends Activity {Button btn1=null;    /** Called when the activity is first created. */    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);        btn1=(Button)findViewById(R.id.btn1);        btn1.setOnClickListener(new Button.OnClickListener(){@Overridepublic void onClick(View v) {// TODO Auto-generated method stubIntent intent=new Intent();intent.setClass(EX03_09.this,EX03_09_01.class);startActivity(intent);EX03_09.this.finish();}                });    }}

Src/EX03_09_01.java

package gphone.ex03_09;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.view.View;import android.widget.Button;public class EX03_09_01 extends Activity{Button btn2=null;@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);this.setContentView(R.layout.ex036_09_01);btn2=(Button)findViewById(R.id.btn2);btn2.setOnClickListener(new Button.OnClickListener(){@Overridepublic void onClick(View v) {// TODO Auto-generated method stubIntent intent=new Intent();intent.setClass(EX03_09_01.this,EX03_09.class);startActivity(intent);EX03_09_01.this.finish();}});}}

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.