附上源码:https://github.com/LiuJingyingdev/StudentSystem
进入正题:
本App用的是LitePal来操作数据库的,比较简单,就是自己学了LitePal后,马上就动手做App了,由于中间遇到了一个非常头疼的事情,就是到一个地方,老是崩溃,弄得我自己都差点放弃了,后来解决了。
主要功能:
- 登录,注册
- 创建数据库
- 学生信息的增删改查(每个学生的信息比较少,就只有学号姓名,其实学会了这个,后面都是造轮子)
首先是界面(就不要吐槽我的界面了,理科生的审美观,真的可怕):
登录界面、主界面
主界面代码:
package com.example.studentsystem;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import org.litepal.LitePal;
public class StudentMenu extends AppCompatActivity implements View.OnClickListener{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.student_menu);
Button addStudent = (Button) findViewById(R.id.add_stu);
Button deleteStudent = (Button) findViewById(R.id.delete_stu);
Button updateStudent = (Button) findViewById(R.id.update_stu);
Button queryStudent = (Button) findViewById(R.id.query_stu);
Button exitSystem = (Button) findViewById(R.id.exit_stu);
addStudent.setOnClickListener(this);
deleteStudent.setOnClickListener(this);
updateStudent.setOnClickListener(this);
queryStudent.setOnClickListener(this);
exitSystem.setOnClickListener(this);
}
@Override
public void onClick(View view){
switch (view.getId()){
case R.id.add_stu:
Intent intent1 = new Intent(StudentMenu.this,AddStudent.class);
startActivity(intent1);
break;
case R.id.delete_stu:
Intent intent2 = new Intent(StudentMenu.this,DeleteStudent.class);
startActivity(intent2);
break;
case R.id.update_stu:
Intent intent3 = new Intent(StudentMenu.this,UpdateStudent.class);
startActivity(intent3);
break;
case R.id.query_stu:
Intent intent4 = new Intent(StudentMenu.this,QueryStudent.class);
startActivity(intent4);
break;
case R.id.exit_stu:
finish();
break;
default:
break;
}
}
}
主界面代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/piture4">
<View
android:layout_width="match_parent"
android:layout_height="80dp"></View>
<Button
android:id="@+id/add_stu"
android:layout_width="130sp"
android:layout_height="40sp"
android:text="增加学生信息"
android:textColor="#ffffff"
android:background="@drawable/shape"
android:layout_gravity="center"/>
<View
android:layout_width="12dp"
android:layout_height="30sp"></View>
<Button
android:id="@+id/delete_stu"
android:layout_width="130sp"
android:layout_height="40sp"
android:text="删除学生信息"
android:textColor="#ffffff"
android:background="@drawable/shape"
android:layout_gravity="center"/>
<View
android:layout_width="12dp"
android:layout_height="30sp"></View>
<Button
android:id="@+id/update_stu"
android:layout_width="130sp"
android:layout_height="40sp"
android:text="更新学生信息"
android:textColor="#ffffff"
android:background="@drawable/shape"
android:layout_gravity="center"/>
<View
android:layout_width="12dp"
android:layout_height="30sp"></View>
<Button
android:id="@+id/query_stu"
android:layout_width="130sp"
android:layout_height="40sp"
android:text="查看学生信息"
android:textColor="#ffffff"
android:background="@drawable/shape"
android:layout_gravity="center"/>
<View
android:layout_width="12dp"
android:layout_height="30sp"></View>
<Button
android:id="@+id/exit_stu"
android:layout_width="130sp"
android:layout_height="40sp"
android:layout_alignParentBottom="true"
android:text="退出学生系统"
android:textColor="#ffffff"
android:background="@drawable/shape"
android:layout_gravity="center"/>
</LinearLayout>
由于有很多个类,我就不全部列出来了,Github已送上,欢迎参考。