【发布时间】:2013-05-14 13:34:53
【问题描述】:
我要上第一个Activity(在布局中写)你叫什么名字?!当一个人在电影中写下他的名字时,它应该出现 Hello(THE NAME)!我该怎么做?
【问题讨论】:
我要上第一个Activity(在布局中写)你叫什么名字?!当一个人在电影中写下他的名字时,它应该出现 Hello(THE NAME)!我该怎么做?
【问题讨论】:
这就是你如何使用参数调用意图
Intent search = new Intent(FirstActivity.this, SecondActivity.class);
search.putExtra("param_a", content1);
startActivity(search);
【讨论】:
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);
}
}
}
【讨论】:
String 对象中。示例:String stringObject="Foo";
myTextView.setText(stringObject);