赞
踩
通过该App可以添加学生的学号、姓名、科目、成绩信息,添加的所有信息可以统一展示出来。
activity_main
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical"
- tools:context="com.example.admin.cs7.ActivityMain">
- <TextView
- android:layout_width="match_parent"
- android:layout_height="60dp"
- android:textColor="#FFFFFF"
- android:background="#FF3F5139"
- android:gravity="center"
- android:textSize="26sp"
- android:text="学生成绩管理系统" />
-
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal">
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="姓名:"
- android:textColor="#000000"
- android:textSize="18sp" />
- <EditText
- android:id="@+id/shu_ji_1"
- android:hint="请输入姓名"
- android:inputType="textPersonName"
- android:layout_width="match_parent"
- android:layout_height="50dp"/>
- </LinearLayout>
-
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal">
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="学号:"
- android:textColor="#000000"
- android:textSize="18sp"
- />
- <EditText
- android:id="@+id/shu_ji_2"
- android:hint="请输入学号"
- android:inputType="phone"
- android:layout_width="match_parent"
- android:layout_height="50dp"/>
- </LinearLayout>
-
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal">
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="科目:"
- android:textColor="#000000"
- android:textSize="18sp"
- />
- <EditText
- android:id="@+id/ke_mu"
- android:hint="请输入课程科目"
- android:layout_width="match_parent"
- android:layout_height="50dp"/>
- </LinearLayout>
-
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal">
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="成绩:"
- android:textColor="#000000"
- android:textSize="18sp"
- />
- <EditText
- android:id="@+id/cheng_ji"
- android:hint="请输入成绩"
- android:inputType="phone"
- android:layout_width="match_parent"
- android:layout_height="50dp"/>
- </LinearLayout>
-
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical">
- <Button
- android:id="@+id/button_1"
- android:text="添加"
- android:textSize="18sp"
- android:textStyle="bold"
- android:layout_width="match_parent"
- android:layout_height="50dp"/>
- <Button
- android:id="@+id/button_2"
- android:text="展示成绩"
- android:textSize="18sp"
- android:textStyle="bold"
- android:layout_width="match_parent"
- android:layout_height="50dp"/>
- </LinearLayout>
- </LinearLayout>
xin_xi
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="horizontal">
-
- <ImageView
- android:id="@+id/image"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:background="@drawable/niao"/>
-
- <TextView
- android:id="@+id/zan_si_1"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_toRightOf="@+id/image"
- android:text="姓名:"/>
- <TextView
- android:id="@+id/shu_ji_1"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_toRightOf="@+id/zan_si_1"/>
- <TextView
- android:id="@+id/zan_si_2"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_below="@+id/zan_si_1"
- android:layout_toRightOf="@+id/image"
- android:text="学号:"/>
- <TextView
- android:id="@+id/shu_ji_2"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_toRightOf="@+id/zan_si_2"
- android:layout_below="@+id/shu_ji_1"/>
-
- <TextView
- android:id="@+id/zan_si_3"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_below="@+id/zan_si_2"
- android:layout_toRightOf="@+id/image"
- android:text="科目:"/>
- <TextView
- android:id="@+id/shu_ji_3"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_toRightOf="@+id/zan_si_3"
- android:layout_below="@+id/shu_ji_2"/>
- <TextView
- android:id="@+id/zan_si_4"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_below="@+id/zan_si_3"
- android:layout_toRightOf="@+id/image"
- android:text="成绩:"/>
-
- <TextView
- android:id="@+id/shu_ji_4"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_toRightOf="@+id/zan_si_4"
- android:layout_below="@+id/shu_ji_3" />
- </RelativeLayout>
zhan_shi
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical"
- tools:context="com.example.admin.cs7.ActivityMain">
- <TextView
- android:layout_width="match_parent"
- android:layout_height="60dp"
- android:textColor="#FFFFFF"
- android:background="#FF3F5139"
- android:gravity="center"
- android:textSize="26sp"
- android:textStyle="bold"
- android:text="成绩展示页面" />
- <ListView
- android:id="@+id/listview"
- android:layout_width="match_parent"
- android:layout_height="600dp">
- </ListView>
-
- <Button
- android:id="@+id/button_3"
- android:text="返回"
- android:textSize="18sp"
- android:layout_width="match_parent"
- android:layout_height="50dp"/>
- </LinearLayout>
ActivityMain
- import android.app.Activity;
- import android.content.Intent;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.ListView;
- import android.widget.SimpleAdapter;
-
- import java.io.Serializable;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
-
- public class ActivityMain extends Activity {
- ArrayList<Student> list1 = new ArrayList<Student>();
- ArrayList<Student> list2 = new ArrayList<Student>();
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
-
- super.onCreate(savedInstanceState);
- setContentView(R.layout.zhan_shi);
- list1= (ArrayList<Student>) getIntent().getSerializableExtra("list");
- list2= (ArrayList<Student>) getIntent().getSerializableExtra("list2");
- if(list2!=null){
- list1.addAll(list2);}
- ListView listview = (ListView) findViewById(R.id.listview); // 获取列表视图
- List<Map<String, Object>> listItems = new ArrayList<Map<String, Object>>();// 创建一个list集合
-
- for(int i=0;i<list1.size();i++) {
-
-
- Map<String, Object> map = new HashMap<String, Object>();
- map.put("名字", (String) list1.get(i).getShu_ju_1());
- map.put("学号", (String) list1.get(i).getShu_ju_2());
- map.put("科目", (String) list1.get(i).getShu_ju_3());
- map.put("成绩", (String) list1.get(i).getShu_ju_4());
-
- listItems.add(map);
- }
-
- SimpleAdapter adapter = new SimpleAdapter(this, listItems,
- R.layout.xin_xi, new String[]{"名字", "学号", "科目", "成绩"}, new int[]{
- R.id.shu_ji_1, R.id.shu_ji_2, R.id.shu_ji_3, R.id.shu_ji_4});
- // 创建SimpleAdapter
- listview.setAdapter(adapter);// 将适配器与ListView关联
-
- Button button = (Button) findViewById(R.id.button_3);
- button.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- Intent intent1 = new Intent();
- intent1.setClass(ActivityMain.this, ActivityStudent.class);
- intent1.putExtra("list1", (Serializable) list1);
- startActivity(intent1);
- }
- });
-
-
- }
- }
ActivityStudent
-
- import android.app.Activity;
- import android.content.Intent;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.Toast;
-
- import java.io.Serializable;
- import java.util.ArrayList;
-
- public class ActivityStudent extends Activity {
-
- Student student=new Student();
- ArrayList<Student> list = new ArrayList<Student>();
- String shu_ji_1 = "";
- String shu_ji_2 = "";
- String shu_ji_3 = "";
- String shu_ji_4 = "";
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- final Button button = (Button) findViewById(R.id.button_2);
- button.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
-
- shu_ji_1 = ((EditText) findViewById(R.id.shu_ji_1)).getText().toString();
- shu_ji_2 = ((EditText) findViewById(R.id.shu_ji_2)).getText().toString();
-
- shu_ji_3 = ((EditText) findViewById(R.id.ke_mu)).getText().toString();
- shu_ji_4 = ((EditText) findViewById(R.id.cheng_ji)).getText().toString();
-
- student.setShu_ju_1(shu_ji_1);
- student.setShu_ju_2(shu_ji_2);
- student.setShu_ju_3(shu_ji_3);
- student.setShu_ju_4(shu_ji_4);
- list.add(student);
- ArrayList<Student> list2= (ArrayList<Student>) getIntent().getSerializableExtra("list1");
- if (!"".equals(shu_ji_1) && !"".equals(shu_ji_2)) {
- Intent intent = new Intent(ActivityStudent.this, ActivityMain.class);
-
- intent.putExtra("list", (Serializable) list);
- if(list2!=null){
- intent.putExtra("list2", (Serializable) list2);
- }
- startActivity(intent);
- } else {
- Toast.makeText(ActivityStudent.this, "请填写完整!!!", Toast.LENGTH_SHORT).show();
- }
- }
- });
-
- }
- }
Student
- import java.io.Serializable;
-
- public class Student implements Serializable {
- private String shu_ju_1;
- private String shu_ju_2;
- private String shu_ju_3 ;
- private String shu_ju_4;
- Student(){
- shu_ju_1 = "张三" ;
- shu_ju_2 = "01" ;
- shu_ju_3 = "语文" ;
- shu_ju_4 = "89" ;
- }
- Student(String shu_ju_1 , String shu_ju_2 , String shu_ju_3 , String shu_ju_4){
- this.shu_ju_1 = shu_ju_1;
- this.shu_ju_2 = shu_ju_2;
- this.shu_ju_3 = shu_ju_3;
- this.shu_ju_4 = shu_ju_4;
- }
- public String getShu_ju_1(){return shu_ju_1;}
- public void setShu_ju_1(String shu_ju_1){this.shu_ju_1 = shu_ju_1;}
-
- public String getShu_ju_2(){return shu_ju_2;}
- public void setShu_ju_2(String shu_ju_2){this.shu_ju_2 = shu_ju_2;}
-
- public String getShu_ju_3(){return shu_ju_3;}
- public void setShu_ju_3(String shu_ju_3){this.shu_ju_3 = shu_ju_3;}
-
- public String getShu_ju_4(){return shu_ju_4;}
- public void setShu_ju_4(String shu_ju_4){this.shu_ju_4 = shu_ju_4;}
- }
运行结果:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。