因为使用的是数据库来储存信息和调用,并没有重写对于listview的Adapter,而是使用Android自带的SimpleCursorAdapter类方法,用游标来储存,查看数据
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" ? ? android:layout_width="match_parent" ? ? android:layout_height="match_parent" ? ? android:orientation="vertical"> ? ? <LinearLayout ? ? ? ? android:layout_width="match_parent" ? ? ? ? android:layout_height="wrap_content" ? ? ? ? android:orientation="horizontal"> ? ? ? ? <TextView ? ? ? ? ? ? android:layout_width="0dp" ? ? ? ? ? ? android:layout_height="50dp" ? ? ? ? ? ? android:layout_weight="1" ? ? ? ? ? ? android:text="id"/> ? ? ? ? ? <TextView ? ? ? ? ? ? android:layout_width="0dp" ? ? ? ? ? ? android:layout_height="50dp" ? ? ? ? ? ? android:layout_weight="1" ? ? ? ? ? ? android:text="姓名" /> ? ? ? ? ? <TextView ? ? ? ? ? ? android:layout_width="0dp" ? ? ? ? ? ? android:layout_height="50dp" ? ? ? ? ? ? android:layout_weight="1" ? ? ? ? ? ? android:text="学号" /> ? ? ? ? ? <TextView ? ? ? ? ? ? android:layout_width="0dp" ? ? ? ? ? ? android:layout_height="50dp" ? ? ? ? ? ? android:layout_weight="1" ? ? ? ? ? ? android:text="班级" /> ? ? ? ? ? <TextView ? ? ? ? ? ? android:layout_width="0dp" ? ? ? ? ? ? android:layout_height="50dp" ? ? ? ? ? ? android:layout_weight="1" ? ? ? ? ? ? android:text="专业" /> ? ? ? ? ? <TextView ? ? ? ? ? ? android:layout_width="0dp" ? ? ? ? ? ? android:layout_height="50dp" ? ? ? ? ? ? android:layout_weight="1" ? ? ? ? ? ? android:text="成绩" /> ? ? ? ? </LinearLayout> ? ? ? <LinearLayout ? ? ? ? android:layout_width="match_parent" ? ? ? ? android:layout_height="wrap_content" ? ? ? ? android:orientation="horizontal"> ? ? ? ? <TextView ? ? ? ? ? ? android:id="@+id/id" ? ? ? ? ? ? android:layout_width="0dp" ? ? ? ? ? ? android:layout_height="50dp" ? ? ? ? ? ? android:layout_weight="1" /> ? ? ? ? ? <TextView ? ? ? ? ? ? android:id="@+id/xm" ? ? ? ? ? ? android:layout_width="0dp" ? ? ? ? ? ? android:layout_height="50dp" ? ? ? ? ? ? android:layout_weight="1" /> ? ? ? ? ? <TextView ? ? ? ? ? ? android:id="@+id/xh" ? ? ? ? ? ? android:layout_width="0dp" ? ? ? ? ? ? android:layout_height="50dp" ? ? ? ? ? ? android:layout_weight="1" /> ? ? ? ? ? <TextView ? ? ? ? ? ? android:id="@+id/bj" ? ? ? ? ? ? android:layout_width="0dp" ? ? ? ? ? ? android:layout_height="50dp" ? ? ? ? ? ? android:layout_weight="1" /> ? ? ? ? ? <TextView ? ? ? ? ? ? android:id="@+id/zy" ? ? ? ? ? ? android:layout_width="0dp" ? ? ? ? ? ? android:layout_height="50dp" ? ? ? ? ? ? android:layout_weight="1" /> ? ? ? ? ? <TextView ? ? ? ? ? ? android:id="@+id/cj" ? ? ? ? ? ? android:layout_width="0dp" ? ? ? ? ? ? android:layout_height="50dp" ? ? ? ? ? ? android:layout_weight="1" /> ? ? </LinearLayout> ? </LinearLayout>
对于新添加学生操作,使用NewStudent.class来完成
package com.example.myapp; ? import androidx.appcompat.app.AppCompatActivity; ? import android.content.Intent; import android.os.Bundle; import android.text.TextUtils; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; ? public class NewStudent extends AppCompatActivity { ? ? DbHelper dbHelper; ? ? ? @Override ? ? protected void onCreate(Bundle savedInstanceState) { ? ? ? ? super.onCreate(savedInstanceState); ? ? ? ? setContentView(R.layout.activity_new_student); ? ? ? ? dbHelper=new DbHelper(NewStudent.this,"MyDataBase",3); ? ? ? ? Intent priIntent = getIntent(); ? ? ? ? ? EditText et_xm = findViewById(R.id.et_xm); ? ? ? ? EditText et_xh = findViewById(R.id.et_xh); ? ? ? ? EditText et_bj = findViewById(R.id.et_bj); ? ? ? ? EditText et_zy = findViewById(R.id.et_zy); ? ? ? ? EditText et_cj = findViewById(R.id.et_cj); ? ? ? ? String priId = priIntent.getStringExtra("id"); ? ? ? ? String prixm = priIntent.getStringExtra("xm"); ? ? ? ? String prixh = priIntent.getStringExtra("xh"); ? ? ? ? String pribj = priIntent.getStringExtra("bj"); ? ? ? ? String prizy = priIntent.getStringExtra("zy"); ? ? ? ? String pricj = priIntent.getStringExtra("cj"); ? ? ? ? et_xm.setText(prixm); ? ? ? ? et_xh.setText(prixh); ? ? ? ? et_bj.setText(pribj); ? ? ? ? et_zy.setText(prizy); ? ? ? ? et_cj.setText(pricj); ? ? ? ? ? Button btn_confirm = findViewById(R.id.btn_confirm); ? ? ? ? ? btn_confirm.setOnClickListener(new View.OnClickListener() { ? ? ? ? ? ? @Override ? ? ? ? ? ? public void onClick(View v) { ? ? ? ? ? ? ? ? EditText et_xm = findViewById(R.id.et_xm); ? ? ? ? ? ? ? ? EditText et_xh = findViewById(R.id.et_xh); ? ? ? ? ? ? ? ? EditText et_bj = findViewById(R.id.et_bj); ? ? ? ? ? ? ? ? EditText et_zy = findViewById(R.id.et_zy); ? ? ? ? ? ? ? ? EditText et_cj = findViewById(R.id.et_cj); ? ? ? ? ? ? ? ? ? String xm = et_xm.getText().toString(); ? ? ? ? ? ? ? ? String xh = et_xh.getText().toString(); ? ? ? ? ? ? ? ? String bj = et_bj.getText().toString(); ? ? ? ? ? ? ? ? String zy = et_zy.getText().toString(); ? ? ? ? ? ? ? ? String cj = et_cj.getText().toString(); ? ? ? ? ? ? ? ? if (TextUtils.isEmpty(xm)||TextUtils.isEmpty(xh)){ ? ? ? ? ? ? ? ? ? ? Toast.makeText(NewStudent.this,"学号或者姓名不可为空",Toast.LENGTH_SHORT).show(); ? ? ? ? ? ? ? ? ? ? return; ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? Intent intent = new Intent(); ? ? ? ? ? ? ? ? intent.putExtra("_id",priId); ? ? ? ? ? ? ? ? intent.putExtra("xm",xm); ? ? ? ? ? ? ? ? intent.putExtra("xh",xh); ? ? ? ? ? ? ? ? intent.putExtra("bj",bj); ? ? ? ? ? ? ? ? intent.putExtra("zy",zy); ? ? ? ? ? ? ? ? intent.putExtra("cj",cj); ? ? ? ? ? ? ? ? setResult(RESULT_OK,intent); ? ? ? ? ? ? ? ? finish(); ? ? ? ? ? ? } ? ? ? ? }); ? ? } }
activity_new_student.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:orientation="vertical" ? ? android:layout_height="match_parent" ? ? tools:context=".NewStudent"> ? ? <EditText ? ? ? ? android:layout_width="match_parent" ? ? ? ? android:layout_height="wrap_content" ? ? ? ? android:id="@+id/et_xm" ? ? ? ? android:hint="请输入姓名" ? ? ? ? /> ? ? <EditText ? ? ? ? android:layout_width="match_parent" ? ? ? ? android:layout_height="wrap_content" ? ? ? ? android:id="@+id/et_xh" ? ? ? ? android:hint="请输入学号" ? ? ? ? /> ? ? <EditText ? ? ? ? android:layout_width="match_parent" ? ? ? ? android:layout_height="wrap_content" ? ? ? ? android:id="@+id/et_bj" ? ? ? ? android:hint="请输入班级" ? ? ? ? /> ? ? <EditText ? ? ? ? android:layout_width="match_parent" ? ? ? ? android:layout_height="wrap_content" ? ? ? ? android:id="@+id/et_zy" ? ? ? ? android:hint="请输入专业" ? ? ? ? /> ? ? <EditText ? ? ? ? android:layout_width="match_parent" ? ? ? ? android:layout_height="wrap_content" ? ? ? ? android:id="@+id/et_cj" ? ? ? ? android:hint="请输入成绩" ? ? ? ? /> ? ? ? <Button ? ? ? ? android:layout_width="match_parent" ? ? ? ? android:layout_height="wrap_content" ? ? ? ? android:id="@+id/btn_confirm" ? ? ? ? android:text="确定" ? ? ? ? /> ? </LinearLayout>
运行效果图:
登录页面:
注册界面:
管理界面:
对listview进行操作:单击
长按
对listview的添加:
标签:SQLite
相关阅读 >>
Sqlitestudio打开后如何切换成简体中文Sqlitestudio绿色版中文设置方法介绍
scp远程vps快速搬家和wdcp升级php5.3安装memcached和eaccelerator教程
更多相关阅读请进入《Sqlite》频道 >>

数据库系统概念 第6版
本书主要讲述了数据模型、基于对象的数据库和XML、数据存储和查询、事务管理、体系结构等方面的内容。