好的,在这种情况下这样做:
Button1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent i = new Intent(YourActivity.this,DetailActivity.class);
i.putExtra("text","Some String for this one");
startActivity(i);
}
});
Button2.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent i = new Intent(YourActivity.this,DetailActivity.class);
i.putExtra("text","Some other String for this one");
startActivity(i);
}
});
如您所见,方法putStringExtra()
表单Intent
允许您发送一些信息。所以在你的DetailActivity
课堂上你可以像这样得到它:
Intent intent = getIntent();
String text = intent.getStringExtra("text");
//and now you have the text you sent in when you created the Activity
因此,您可以使您DetailActivity
的内容显示与意图的附加内容一起发送的任何内容。