+ -
当前位置:首页 → 问答吧 → android Bundle使用

android Bundle使用

时间:2011-09-06

来源:互联网

Bundle可以携带一些其他型别的东西吗? 像Matcher类别或是自订的类别~,如果有怎么携带

作者: 銀狐浪人   发布时间: 2011-09-06

:::自订类别
1
2
3
4
5
public class Student implements Serializable
{ public String name; public int score;
}


画面1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
public class MySource extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);
  Button button=(Button)findViewById(R.id.button1); button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Student student=new Student(); student.name="ABC"; student.score=99; Bundle bundle=new Bundle(); bundle.putSerializable("Student", student); Intent intent=new Intent(); intent.setClass(MySource.this, MySource_2.class); intent.putExtras(bundle); startActivity(intent); } }); }
 
}


画面2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
public class MySource_2 extends Activity
{ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_2); Student student=(Student)getIntent().getExtras().getSerializable("Student"); this.setTitle(student.name +" "+student.score); }
}

作者: luo673   发布时间: 2011-09-07

热门下载

更多