android——学生信息显示和添加
学生类
package com.example.test;
import android.widget.RadioButton;
import java.io.Serializable;
/**
* Created by TBM on 2021/3/14
*/
public class Student implements Serializable {
private String name;
private String age;
private String major;
private String sex;
private String xy;
private String time;
private String[] course;
Student(String name, String age,String sex,String major,String xy,String time,String[] course){
this.name = name;
this.major =major;
this.age = age;
this.sex = sex;
this.xy = xy;
this.time = time;
this.course = course;
}
public String getName(){
return name;}
public void setName(String name){
this.name = name;}
public String getMajor(){
return major;}
public void setMajor(String major){
this.major = major;}
public String getAge(){
return age;}
public void setAge(String age){
this.age = age;}
public String getSex(){
return sex;}
public void setSex(String sex){
this.sex = sex;}
public String getXy(){
return xy;}
public void setXy(String xy){
this.xy = xy;}
public String getTime() {
return time;
}
public String[] getCourse() {
return course;
}
public void setCourse(String[] course) {
this.course = course;
}
}
使用ListView显示学生信息
主界面布局.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<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:textSize="24sp"
android:layout_gravity="center"
android:textColor="@color/black"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="150dp"
android:id="@+id/btn_add"
android:text="添加学生" />
</LinearLayout>
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/studentList"
android:layout_marginTop="15dp" />
</LinearLayout>
学生信息显示ListView格式.xml文件
<?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">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="李四"
android:id="@+id/name"
android:textSize="25sp"
android:gravity="center"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/major"
android:layout_below="@id/name"
android:textSize="20sp"
android:text="计算机科学与技术"
android:layout_marginTop="10dp"
android:gravity="center"/>
</LinearLayout>
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:id="@+id/delete"
android:layout_alignParentRight="true"
android:src="@drawable/delete"
android:clickable="true"
android:layout_centerInParent="true"/>
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:id="@+id/edit"
android:layout_toLeftOf="@id/delete"
android:layout_marginRight="5dp"
android:layout_centerInParent="true"
android:src="@drawable/edit"
android:clickable="true"/>
</RelativeLayout>
学生信息显示.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://sc