zoukankan      html  css  js  c++  java
  • android用Intent实现Activity跳转 java程序员

    package com.example.intenttest;
    
    import android.os.Bundle;
    import android.app.Activity;
    import android.content.Intent;
    import android.view.Menu;
    import android.view.View;
    import android.widget.Button;
    
    public class MainActivity extends Activity {
    
    	@Override
    	protected void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		setContentView(R.layout.main);
    		Button btn1=(Button)findViewById(R.id.b1);
    		btn1.setOnClickListener(new Button.OnClickListener()
    		{
    			public void onClick(View view)
    			{
    				Intent intent=new Intent();
    				intent.setClass(MainActivity.this,Test.class);
    				startActivity(intent);
    				MainActivity.this.finish();
    			}
    		});
    	}
    
    	@Override
    	public boolean onCreateOptionsMenu(Menu menu) {
    		// Inflate the menu; this adds items to the action bar if it is present.
    		getMenuInflater().inflate(R.menu.main, menu);
    		return true;
    	}
    
    }
    



     

    package com.example.intenttest;
    
    import android.os.Bundle;
    import android.app.Activity;
    import android.content.Intent;
    import android.view.Menu;
    import android.view.View;
    import android.widget.Button;
    
    public class Test extends Activity {
    
    	@Override
    	protected void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		setContentView(R.layout.test);
    		Button btn2=(Button)findViewById(R.id.b2);
    		btn2.setOnClickListener(new Button.OnClickListener()
    		{
    			public void onClick(View view)
    			{
    				Intent intent=new Intent();
    				intent.setClass(Test.this,MainActivity.class);
    				startActivity(intent);
    				Test.this.finish();
    			}
    		});
    	}
    	@Override
    	public boolean onCreateOptionsMenu(Menu menu) {
    		// Inflate the menu; this adds items to the action bar if it is present.
    		getMenuInflater().inflate(R.menu.main, menu);
    		return true;
    	}
    
    }
    


     

  • 相关阅读:
    Spring Boot 缓存技术:Spring Boot
    Java基础之Iterable接口
    使用sqlyog连接 Mysql 出现1251错误
    IDEA更改主题插件——Material Theme UI详解
    免安装版的Mysql
    使用Nexus搭建Maven私服
    Spring之注解注入bean
    Idea springboot 配置热部署
    Spring Boot 异常处理与单元测试
    Ubuntu20.04在线安装VMware-Tools
  • 原文地址:https://www.cnblogs.com/java20130725/p/3215869.html
Copyright © 2011-2022 走看看