JAVA日报

Posted 我的未来姓栗山

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JAVA日报相关的知识,希望对你有一定的参考价值。

换汤不换药之家庭记账本app开发(dao)

package dao;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import java.util.ArrayList;
import java.util.List;

import bean.user;
import sqlite.db;
public class userdao {
public double eat=0;
public double play=0;
public double clothes=0;
public double live=0;
public double usual=0;
public double total=0;
private final db Db;
private static userdao userDao=null;
private userdao(Context context){
Db =new db(context);
}
public static userdao getInstance(Context context){
if(userDao==null){
userDao=new userdao(context);
}
return userDao;
}
public db getDb() {
return Db;
}
//保存
public void insert(user u){
SQLiteDatabase db=Db.getWritableDatabase();
ContentValues values=new ContentValues();
values.put("date",u.get("date"));
values.put("eat",u.get("eat"));
values.put("play",u.get("play"));
values.put("clothes",u.get("clothes"));
values.put("live",u.get("live"));
values.put("usual",u.get("usual"));
db.insert("tex",null,values);
db.close();
}
//获取
public void delete(String id) {
SQLiteDatabase db =Db.getWritableDatabase();
if (db.isOpen()) {
db.execSQL("delete from tex where date=?", new Object[]{id});
db.close();
}
}//删除
public List<user> findAll(){
SQLiteDatabase db=Db.getWritableDatabase();
Cursor cursor=db.query("tex",new String[]{"date","eat","play","clothes","live","usual"},null,null,null,null,null);
List<user> userList=new ArrayList<>();
while(cursor.moveToNext()){
user u=new user();
u.setDate(cursor.getString(0));
u.setEat(cursor.getString(1));
u.setPlay(cursor.getString(2));
u.setClothes(cursor.getString(3));
u.setLive(cursor.getString(4));
u.setUsual(cursor.getString(5));
//Log.e("sqliteshow",user.getName()+" "+user.getDate()+" "+user.getTime()+" "+user.getTem()+" "+user.getArea());
userList.add(u);
}
total=eat+play+clothes+live+usual;
db.close();
return userList;
}
public void Initdata(){
SQLiteDatabase db=Db.getWritableDatabase();
Cursor cursor=db.query("tex",new String[]{"date","eat","play","clothes","live","usual"},null,null,null,null,null);
while(cursor.moveToNext()){
eat = eat + Double.valueOf(cursor.getString(1));
play = play + Double.valueOf(cursor.getString(2));
clothes = clothes + Double.valueOf(cursor.getString(3));
live = live + Double.valueOf(cursor.getString(4));
usual = usual + Double.valueOf(cursor.getString(5));
}
total=eat+play+clothes+live+usual;
db.close();
}
public void clear(){
eat=0;play=0;clothes=0;live=0;usual=0;total=0;
}
}

以上是关于JAVA日报的主要内容,如果未能解决你的问题,请参考以下文章

java代码在片段活动中不起作用

java 代码片段【JAVA】

CSDN日报20170413 ——《天天写业务代码的那些年,我们是如何成长过来的》

# Java 常用代码片段

# Java 常用代码片段

创建片段而不从 java 代码实例化它