Android入门之Activity跳转

public class MainActivity extends Activity {

	
//	private Button button01;  //定义按钮   页可以不定义  在后面使用的时候  直接
//	private Button button02;
	
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);             //绑定布局
//        button01=(Button)this.findViewById(R.layout.button1);
        
      Button  button01 =(Button)this.findViewById(R.id.button1);   //为按钮绑定
      Button  button02 =(Button)this.findViewById(R.id.button2);   //为按钮绑定
      Button  button03 =(Button)this.findViewById(R.id.button3);
        button01.setOnClickListener(new View.OnClickListener() {                   //设置事件监听器   
			
			@Override
			public void onClick(View v) { 
				// TODO Auto-generated method stub      TODO 用来说明这个是自动生成的
				/*Intent intent1=new Intent(MainActivity.this,NextActivity.class);   //设置Activity跳转
				startActivity(intent1);    */            //启动intent
				startActivity(new Intent("android.settings.WIFI_DISPLAY_SETTINGS"));
			}
		});
        
        button02.setOnClickListener(new View.OnClickListener() {                   //设置事件监听器   
        	
        	@Override
        	public void onClick(View v) { 
        		// TODO Auto-generated method stub
				Intent intent2=new Intent(MainActivity.this,ThirdActivity.class);   //<span style="color:#ff0000;">设置Activity跳转</span>
				
				startActivity(intent2);                //启动intent
				
//        		startActivity(new Intent(MainActivity.this,ThirdActivity.class) );   
        	}
        });
         
         button03.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
		Intent	intent3= new Intent(MainActivity.this,FourthActivity.class);
				startActivity(intent3);
				
				intent3.putExtra("name", "Syber");
				intent3.putExtra("age", 23);
				intent3.putExtra("address", "成都");           //为intent1 传入值
				
				
				Bundle bundle1=new Bundle();
				bundle1.putString("code", "10086");         //放入一个Bundle键值
				
				
				intent3.putExtra("bundle", bundle1);              //为intent1 传入之前定义好的键值
			}
			
		});
        
        
    }


    @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;
    }
    
}



你可能感兴趣的:(Android入门之Activity跳转)