一、button链接到另一个Activity
1、java包中创建activity类:
a、创建Activity类
b、创建布局资源文件
c、AndroidMainfest.xml中注册配置标签
2、主页面中添加Button
a、长、宽
b、id、text
3、MainActivity中添加监听:
方法1:
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); System.out.println("A onCreate"); findViewById(R.id.btnBAty).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { startActivity(new Intent(MainActivity.this,BAty.class)); } }); }
方法2:
private Activity self = this; private Button button; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); button = (Button) findViewById(R.id.btnStartAty); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(self,TheAty.class); self.startActivity(i); //self.finish();//跳转后自杀 } }); }
二、Activity之间传递参数:
1、发送参数: