当前位置:   article > 正文

Android 简单的学生成绩管理系统

Android 简单的学生成绩管理系统

 

        通过该App可以添加学生的学号、姓名、科目、成绩信息,添加的所有信息可以统一展示出来。

 activity_main 

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:tools="http://schemas.android.com/tools"
  4. android:layout_width="match_parent"
  5. android:layout_height="match_parent"
  6. android:orientation="vertical"
  7. tools:context="com.example.admin.cs7.ActivityMain">
  8. <TextView
  9. android:layout_width="match_parent"
  10. android:layout_height="60dp"
  11. android:textColor="#FFFFFF"
  12. android:background="#FF3F5139"
  13. android:gravity="center"
  14. android:textSize="26sp"
  15. android:text="学生成绩管理系统" />
  16. <LinearLayout
  17. android:layout_width="match_parent"
  18. android:layout_height="wrap_content"
  19. android:orientation="horizontal">
  20. <TextView
  21. android:layout_width="wrap_content"
  22. android:layout_height="wrap_content"
  23. android:text="姓名:"
  24. android:textColor="#000000"
  25. android:textSize="18sp" />
  26. <EditText
  27. android:id="@+id/shu_ji_1"
  28. android:hint="请输入姓名"
  29. android:inputType="textPersonName"
  30. android:layout_width="match_parent"
  31. android:layout_height="50dp"/>
  32. </LinearLayout>
  33. <LinearLayout
  34. android:layout_width="match_parent"
  35. android:layout_height="wrap_content"
  36. android:orientation="horizontal">
  37. <TextView
  38. android:layout_width="wrap_content"
  39. android:layout_height="wrap_content"
  40. android:text="学号:"
  41. android:textColor="#000000"
  42. android:textSize="18sp"
  43. />
  44. <EditText
  45. android:id="@+id/shu_ji_2"
  46. android:hint="请输入学号"
  47. android:inputType="phone"
  48. android:layout_width="match_parent"
  49. android:layout_height="50dp"/>
  50. </LinearLayout>
  51. <LinearLayout
  52. android:layout_width="match_parent"
  53. android:layout_height="wrap_content"
  54. android:orientation="horizontal">
  55. <TextView
  56. android:layout_width="wrap_content"
  57. android:layout_height="wrap_content"
  58. android:text="科目:"
  59. android:textColor="#000000"
  60. android:textSize="18sp"
  61. />
  62. <EditText
  63. android:id="@+id/ke_mu"
  64. android:hint="请输入课程科目"
  65. android:layout_width="match_parent"
  66. android:layout_height="50dp"/>
  67. </LinearLayout>
  68. <LinearLayout
  69. android:layout_width="match_parent"
  70. android:layout_height="wrap_content"
  71. android:orientation="horizontal">
  72. <TextView
  73. android:layout_width="wrap_content"
  74. android:layout_height="wrap_content"
  75. android:text="成绩:"
  76. android:textColor="#000000"
  77. android:textSize="18sp"
  78. />
  79. <EditText
  80. android:id="@+id/cheng_ji"
  81. android:hint="请输入成绩"
  82. android:inputType="phone"
  83. android:layout_width="match_parent"
  84. android:layout_height="50dp"/>
  85. </LinearLayout>
  86. <LinearLayout
  87. android:layout_width="match_parent"
  88. android:layout_height="wrap_content"
  89. android:orientation="vertical">
  90. <Button
  91. android:id="@+id/button_1"
  92. android:text="添加"
  93. android:textSize="18sp"
  94. android:textStyle="bold"
  95. android:layout_width="match_parent"
  96. android:layout_height="50dp"/>
  97. <Button
  98. android:id="@+id/button_2"
  99. android:text="展示成绩"
  100. android:textSize="18sp"
  101. android:textStyle="bold"
  102. android:layout_width="match_parent"
  103. android:layout_height="50dp"/>
  104. </LinearLayout>
  105. </LinearLayout>

xin_xi

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:orientation="horizontal">
  6. <ImageView
  7. android:id="@+id/image"
  8. android:layout_width="wrap_content"
  9. android:layout_height="wrap_content"
  10. android:background="@drawable/niao"/>
  11. <TextView
  12. android:id="@+id/zan_si_1"
  13. android:layout_width="wrap_content"
  14. android:layout_height="wrap_content"
  15. android:layout_toRightOf="@+id/image"
  16. android:text="姓名:"/>
  17. <TextView
  18. android:id="@+id/shu_ji_1"
  19. android:layout_width="wrap_content"
  20. android:layout_height="wrap_content"
  21. android:layout_toRightOf="@+id/zan_si_1"/>
  22. <TextView
  23. android:id="@+id/zan_si_2"
  24. android:layout_width="wrap_content"
  25. android:layout_height="wrap_content"
  26. android:layout_below="@+id/zan_si_1"
  27. android:layout_toRightOf="@+id/image"
  28. android:text="学号:"/>
  29. <TextView
  30. android:id="@+id/shu_ji_2"
  31. android:layout_width="wrap_content"
  32. android:layout_height="wrap_content"
  33. android:layout_toRightOf="@+id/zan_si_2"
  34. android:layout_below="@+id/shu_ji_1"/>
  35. <TextView
  36. android:id="@+id/zan_si_3"
  37. android:layout_width="wrap_content"
  38. android:layout_height="wrap_content"
  39. android:layout_below="@+id/zan_si_2"
  40. android:layout_toRightOf="@+id/image"
  41. android:text="科目:"/>
  42. <TextView
  43. android:id="@+id/shu_ji_3"
  44. android:layout_width="wrap_content"
  45. android:layout_height="wrap_content"
  46. android:layout_toRightOf="@+id/zan_si_3"
  47. android:layout_below="@+id/shu_ji_2"/>
  48. <TextView
  49. android:id="@+id/zan_si_4"
  50. android:layout_width="wrap_content"
  51. android:layout_height="wrap_content"
  52. android:layout_below="@+id/zan_si_3"
  53. android:layout_toRightOf="@+id/image"
  54. android:text="成绩:"/>
  55. <TextView
  56. android:id="@+id/shu_ji_4"
  57. android:layout_width="wrap_content"
  58. android:layout_height="wrap_content"
  59. android:layout_toRightOf="@+id/zan_si_4"
  60. android:layout_below="@+id/shu_ji_3" />
  61. </RelativeLayout>

zhan_shi

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:tools="http://schemas.android.com/tools"
  4. android:layout_width="match_parent"
  5. android:layout_height="match_parent"
  6. android:orientation="vertical"
  7. tools:context="com.example.admin.cs7.ActivityMain">
  8. <TextView
  9. android:layout_width="match_parent"
  10. android:layout_height="60dp"
  11. android:textColor="#FFFFFF"
  12. android:background="#FF3F5139"
  13. android:gravity="center"
  14. android:textSize="26sp"
  15. android:textStyle="bold"
  16. android:text="成绩展示页面" />
  17. <ListView
  18. android:id="@+id/listview"
  19. android:layout_width="match_parent"
  20. android:layout_height="600dp">
  21. </ListView>
  22. <Button
  23. android:id="@+id/button_3"
  24. android:text="返回"
  25. android:textSize="18sp"
  26. android:layout_width="match_parent"
  27. android:layout_height="50dp"/>
  28. </LinearLayout>

ActivityMain

  1. import android.app.Activity;
  2. import android.content.Intent;
  3. import android.os.Bundle;
  4. import android.view.View;
  5. import android.widget.Button;
  6. import android.widget.ListView;
  7. import android.widget.SimpleAdapter;
  8. import java.io.Serializable;
  9. import java.util.ArrayList;
  10. import java.util.HashMap;
  11. import java.util.List;
  12. import java.util.Map;
  13. public class ActivityMain extends Activity {
  14. ArrayList<Student> list1 = new ArrayList<Student>();
  15. ArrayList<Student> list2 = new ArrayList<Student>();
  16. @Override
  17. protected void onCreate(Bundle savedInstanceState) {
  18. super.onCreate(savedInstanceState);
  19. setContentView(R.layout.zhan_shi);
  20. list1= (ArrayList<Student>) getIntent().getSerializableExtra("list");
  21. list2= (ArrayList<Student>) getIntent().getSerializableExtra("list2");
  22. if(list2!=null){
  23. list1.addAll(list2);}
  24. ListView listview = (ListView) findViewById(R.id.listview); // 获取列表视图
  25. List<Map<String, Object>> listItems = new ArrayList<Map<String, Object>>();// 创建一个list集合
  26. for(int i=0;i<list1.size();i++) {
  27. Map<String, Object> map = new HashMap<String, Object>();
  28. map.put("名字", (String) list1.get(i).getShu_ju_1());
  29. map.put("学号", (String) list1.get(i).getShu_ju_2());
  30. map.put("科目", (String) list1.get(i).getShu_ju_3());
  31. map.put("成绩", (String) list1.get(i).getShu_ju_4());
  32. listItems.add(map);
  33. }
  34. SimpleAdapter adapter = new SimpleAdapter(this, listItems,
  35. R.layout.xin_xi, new String[]{"名字", "学号", "科目", "成绩"}, new int[]{
  36. R.id.shu_ji_1, R.id.shu_ji_2, R.id.shu_ji_3, R.id.shu_ji_4});
  37. // 创建SimpleAdapter
  38. listview.setAdapter(adapter);// 将适配器与ListView关联
  39. Button button = (Button) findViewById(R.id.button_3);
  40. button.setOnClickListener(new View.OnClickListener() {
  41. @Override
  42. public void onClick(View view) {
  43. Intent intent1 = new Intent();
  44. intent1.setClass(ActivityMain.this, ActivityStudent.class);
  45. intent1.putExtra("list1", (Serializable) list1);
  46. startActivity(intent1);
  47. }
  48. });
  49. }
  50. }

ActivityStudent

  1. import android.app.Activity;
  2. import android.content.Intent;
  3. import android.os.Bundle;
  4. import android.view.View;
  5. import android.widget.Button;
  6. import android.widget.EditText;
  7. import android.widget.Toast;
  8. import java.io.Serializable;
  9. import java.util.ArrayList;
  10. public class ActivityStudent extends Activity {
  11. Student student=new Student();
  12. ArrayList<Student> list = new ArrayList<Student>();
  13. String shu_ji_1 = "";
  14. String shu_ji_2 = "";
  15. String shu_ji_3 = "";
  16. String shu_ji_4 = "";
  17. @Override
  18. protected void onCreate(Bundle savedInstanceState) {
  19. super.onCreate(savedInstanceState);
  20. setContentView(R.layout.activity_main);
  21. final Button button = (Button) findViewById(R.id.button_2);
  22. button.setOnClickListener(new View.OnClickListener() {
  23. @Override
  24. public void onClick(View view) {
  25. shu_ji_1 = ((EditText) findViewById(R.id.shu_ji_1)).getText().toString();
  26. shu_ji_2 = ((EditText) findViewById(R.id.shu_ji_2)).getText().toString();
  27. shu_ji_3 = ((EditText) findViewById(R.id.ke_mu)).getText().toString();
  28. shu_ji_4 = ((EditText) findViewById(R.id.cheng_ji)).getText().toString();
  29. student.setShu_ju_1(shu_ji_1);
  30. student.setShu_ju_2(shu_ji_2);
  31. student.setShu_ju_3(shu_ji_3);
  32. student.setShu_ju_4(shu_ji_4);
  33. list.add(student);
  34. ArrayList<Student> list2= (ArrayList<Student>) getIntent().getSerializableExtra("list1");
  35. if (!"".equals(shu_ji_1) && !"".equals(shu_ji_2)) {
  36. Intent intent = new Intent(ActivityStudent.this, ActivityMain.class);
  37. intent.putExtra("list", (Serializable) list);
  38. if(list2!=null){
  39. intent.putExtra("list2", (Serializable) list2);
  40. }
  41. startActivity(intent);
  42. } else {
  43. Toast.makeText(ActivityStudent.this, "请填写完整!!!", Toast.LENGTH_SHORT).show();
  44. }
  45. }
  46. });
  47. }
  48. }

Student

  1. import java.io.Serializable;
  2. public class Student implements Serializable {
  3. private String shu_ju_1;
  4. private String shu_ju_2;
  5. private String shu_ju_3 ;
  6. private String shu_ju_4;
  7. Student(){
  8. shu_ju_1 = "张三" ;
  9. shu_ju_2 = "01" ;
  10. shu_ju_3 = "语文" ;
  11. shu_ju_4 = "89" ;
  12. }
  13. Student(String shu_ju_1 , String shu_ju_2 , String shu_ju_3 , String shu_ju_4){
  14. this.shu_ju_1 = shu_ju_1;
  15. this.shu_ju_2 = shu_ju_2;
  16. this.shu_ju_3 = shu_ju_3;
  17. this.shu_ju_4 = shu_ju_4;
  18. }
  19. public String getShu_ju_1(){return shu_ju_1;}
  20. public void setShu_ju_1(String shu_ju_1){this.shu_ju_1 = shu_ju_1;}
  21. public String getShu_ju_2(){return shu_ju_2;}
  22. public void setShu_ju_2(String shu_ju_2){this.shu_ju_2 = shu_ju_2;}
  23. public String getShu_ju_3(){return shu_ju_3;}
  24. public void setShu_ju_3(String shu_ju_3){this.shu_ju_3 = shu_ju_3;}
  25. public String getShu_ju_4(){return shu_ju_4;}
  26. public void setShu_ju_4(String shu_ju_4){this.shu_ju_4 = shu_ju_4;}
  27. }

运行结果: 

 

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/122369?site
推荐阅读
相关标签
  

闽ICP备14008679号