移动端疫情展示
在原来网页版的基础上,又尝试开发出移动端的。首先移动端相较于网页端有很大的不同,在开发中也有过很多的尝试,主要是数据库的操作相较于网页端有很大的差距,APP使用的是自带的数据库管理工具。
主要源码:package com.example.justloginregistertest;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import java.util.ArrayList;
/public class DBOpenHelper extends SQLiteOpenHelper {
private SQLiteDatabase db;
public DBOpenHelper(Context context){
super(context,"db_test",null,1);
db = getReadableDatabase();
}
@Override
public void onCreate(SQLiteDatabase db){
db.execSQL("CREATE TABLE IF NOT EXISTS user(" +
"_id INTEGER PRIMARY KEY AUTOINCREMENT," +
"name TEXT," +
"password TEXT)");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion){
db.execSQL("DROP TABLE IF EXISTS user");
onCreate(db);
}
public void add(String name,String password){
db.execSQL("INSERT INTO user (name,password) VALUES(?,?)",new Object[]{name,password});
}
public void delete(String name,String password){
db.execSQL("DELETE FROM user WHERE name = AND password ="+name+password);
}
public void updata(String password){
db.execSQL("UPDATE user SET password = ?",new Object[]{password});
}
public ArrayList<User> getAllData(){
ArrayList<User> list = new ArrayList<User>();
Cursor cursor = db.query("user",null,null,null,null,null,"name DESC");
while(cursor.moveToNext()){
String name = cursor.getString(cursor.getColumnIndex("name"));
String password = cursor.getString(cursor.getColumnIndex("password"));
list.add(new User(name,password));
}
return list;
}
}