关于Activity组件的页面之间的传值
//按钮
private Button btnStratAty1;
//文本
private TextView tvOut;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//把Activity和你的布局先绑定起来
setContentView(R.layout.activity_main);
//通过id得到textView
tvOut=(TextView) findViewById(R.id.tvOut);
//通过id查找获得按钮
btnStratAty1=(Button) findViewById(R.id.btnStartAty1);
//给按钮设置时间监听器
btnStratAty1.setOnClickListener(new View.OnClickListener() {//匿名内部类
@Override
public void onClick(View arg0) {
//单击时启动Aty1页面
Intent i=new Intent(MainActivity.this,Aty1.class);
//i.putExtra("txt", "Hello Aty1");
Bundle data=new Bundle();
data.putString("txt", "Hello Aty1(android)");
i.putExtras(data);
//传输数据
// startActivity(i);
//回调数据
startActivityForResult(i, 0);
}
});
System.out.println("创建");
}
==================================================================================================
package cn.eoe.helloworld;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class Aty1 extends Activity {
//创建TxT文本对象
private TextView tvOut;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//将页面layout和视图绑定在Activity
setContentView(R.layout.aty1);
tvOut=(TextView) findViewById(R.id.aty1);
tvOut.setText(getIntent().getStringExtra("txt"));
}
}