zoukankan      html  css  js  c++  java
  • Activity到另一个Acivity

    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="这是第一个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="这是第二个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="116dip" 
        		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(){
    
    			@Override
    			public void onClick(View v) {
    				// TODO Auto-generated method stub
    				Intent 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;
    	@Override
    	protected void onCreate(Bundle savedInstanceState) {
    		// TODO Auto-generated method stub
    		super.onCreate(savedInstanceState);
    		this.setContentView(R.layout.ex036_09_01);
    		
    		btn2=(Button)findViewById(R.id.btn2);
    		btn2.setOnClickListener(new Button.OnClickListener(){
    
    			@Override
    			public void onClick(View v) {
    				// TODO Auto-generated method stub
    				Intent intent=new Intent();
    				intent.setClass(EX03_09_01.this,EX03_09.class);
    				startActivity(intent);
    				EX03_09_01.this.finish();
    				
    			}
    			
    		});
    		
    	}
    	
    }
  • 相关阅读:
    ubuntu下使用sudo 出现unable to resolve host 解决方法
    Ubuntu下使用mysqli-connect连接mysql时报错:ERROR 1698 (28000): Access denied for user 'root'@'localhost'
    Ubuntu下安装LNMP之独立添加php扩展模块
    Ubuntu下安装LNMP之Mysql的安装及卸载
    Ubuntu下安装LNMP之php7的安装并配置Nginx支持php及卸载php
    Ubuntu使用vim编辑器时出现上下左右键变成ABCD
    Ubuntu下安装LNMP之nginx的卸载
    Ubuntu下使用find / -name aaa* 提示“find: 路径必须在表达式之前: XXXX”
    Ubuntu下安装LNMP之nginx的安装
    ubuntu使用su切换root用户提示“认证失败”
  • 原文地址:https://www.cnblogs.com/AlexCheng/p/2120048.html
Copyright © 2011-2022 走看看