public class ShowStudentActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.student_info); Intent intent = getIntent(); Student student = (Student) intent.getSerializableExtra(TableContanst.STUDENT_TABLE); ((TextView)findViewById(R.id.tv_info_id)).setText(student.getId()+""); ((TextView)findViewById(R.id.tv_info_name)).setText(student.getName()); ((TextView)findViewById(R.id.tv_info_age)).setText(student.getAge()+""); ((TextView)findViewById(R.id.tv_info_sex)).setText(student.getSex()); ((TextView)findViewById(R.id.tv_info_likes)).setText(student.getLike()); ((TextView)findViewById(R.id.tv_info_train_date)).setText(student.getTrainDate()); ((TextView)findViewById(R.id.tv_info_phone)).setText(student.getPhoneNumber()); } public void goBack(View view) { finish(); } }
时间: 2024-04-26 18:21:56 浏览: 125
这段代码是一个显示学生信息的Activity类。在onCreate()方法中,通过setContentView()方法设置布局文件,将学生信息显示在界面上。其中,通过Intent获取从其他Activity传递过来的学生对象,并将其各个属性值分别设置到对应的TextView上。最后,通过goBack()方法实现返回上一个Activity的功能。需要注意的是,这里的Student对象需要实现Serializable接口才能被Intent传递。
阅读全文