我想在第一个Activity(在布局中写)你的名字是什么?!当一个人在电影到anther活动时写下自己的名字时,它应该显示为Hello(THE NAME)!我该怎么做?
答案 0 :(得分:3)
这是使用参数
调用intent的方法Intent search = new Intent(FirstActivity.this, SecondActivity.class);
search.putExtra("param_a", content1);
startActivity(search);
答案 1 :(得分:2)
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
//some stuff
//Note : start the activity from an event (onClick per example)
String stringObject = "Foo"; //or a String you get from your editText
Intent i = new Intent(MainActivity.this, OtherActivity.class);
i.putExtra("name", stringObject);
startActivity(i);
}
}
public class OtherActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
//some stuff
Bundle extras = getIntent().getExtras();
String name = "";
if (extras != null){
name = extras.getString("name");
myTextView.setText(name);
}
}
}