传递信息的页面

Intent intent = new Intent(MainActivity.this,ScowlViewActivity.class);//实现MainActivity向ScowlViewActivity跳转
Bundle bundle = new Bundle();//定义Bundle对象存储要传递的值
EditText edit = (EditText)findViewById(R.id.edit);//获取EditText的id
String text = edit.getText().toString();//获取EditText中输入的值,toString()是指将其转换成String型
bundle.putString("name",text);//将name的值传递出去
intent.putExtras(bundle);将bundle对象给intent
startActivity(intent);                       

接收信息的页面

super.onCreate(savedInstanceState);
setContentView(R.layout.scorl_view);
Bundle bundle=this.getIntent().getExtras();//获取bundle对象
String name = bundle.getString("name");//读取传递的值
TextView text = findViewById(R.id.textView);
text.setText(name);//将该值显示在TextView控件中

相关文章:

  • 2022-12-23
  • 2021-10-18
  • 2022-02-10
  • 2021-10-20
猜你喜欢
  • 2022-01-07
  • 2021-10-08
  • 2022-01-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案