通过intent.putExra()来传递数据
新的Activity通过
Intent intent = getInten();
例如
//Item单击事件,单击后跳转到新的Activyty,并显示完整的内容
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
//获取当前Item的完整数据
Blog bg = blogList.get(position);
String tile = bg.getBlogTile();
String contents =bg.getBlogText();
//开始一个新的intent
Intent intent = new Intent(PULLParserActivity.this, BlogActivity.class);
intent.putExtra(KEY_TILE, tile);
intent.putExtra(KEY_CONTENTS, contents);
startActivity(intent);
}
新的Activity里
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_blog);
//接受intent数据
Intent intent = getIntent();
String tile = intent.getStringExtra(KEY_TILE);
String contents = intent.getStringExtra(KEY_CONTENTS);
tvTile = (TextView) findViewById(R.id.textView_tile2);
tvContents = (TextView) findViewById(R.id.textView_contents2);
tvTile.setText(tile);
tvContents.setText(contents);
}