[Android] Android 使用 Greendao 操作 db sqlite(1)-- 直接在MainActivity中调用
继续接上文:
Android 使用 Greendao 操作 db sqlite
布局文件:
activity_test_green.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".TestGreenActivity"> <Button
android:id="@+id/btn_all"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="optGreen"
android:text="获取所有" /> <Button
android:id="@+id/btn_add"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="optGreen"
android:text="添加数据" /> <Button
android:id="@+id/btn_update"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="optGreen"
android:text="更新数据" /> <Button
android:id="@+id/btn_del"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="optGreen"
android:text=" 删除数据" /> <Button
android:id="@+id/btn_clear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="optGreen"
android:text=" 清除数据" /> </LinearLayout>
调用代码:
package com.jack.testmd; import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View; import com.jack.testmd.application.MyApplication;
import com.jack.testmd.greendao.DBManager;
import com.jack.testmd.greendao.UserInfoDao;
import com.jack.testmd.model.UserInfo; import java.util.List; public class TestGreenActivity extends AppCompatActivity {
private final String TAG = DBManager.class.getSimpleName();
private UserInfoDao userInfoDao = DBManager.get().getUserInfoDao(); @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test_green);
} protected void optGreen(View v) { switch (v.getId()) {
case R.id.btn_all:
List<UserInfo> list = userInfoDao.loadAll();
for (int i = 0; i < list.size(); i++) {
Log.i(TAG, "id:" + list.get(i).getId() + ",name:" + list.get(i).getUserName() + ",age:" + list.get(i).getAge());
}
break;
case R.id.btn_add:
UserInfo userInfo = new UserInfo(1, "a001", 10);
userInfoDao.insert(userInfo);
break;
case R.id.btn_update:
UserInfo userInfo2 = new UserInfo(1, "b001", 10);
userInfoDao.update(userInfo2);
break;
case R.id.btn_del:
userInfoDao.deleteByKey((long) 1);
break;
case R.id.btn_clear:
userInfoDao.deleteAll();
break;
}
}
}
方法二:封装DaoUtils类,然后在MainActivity中调用DaoUtils
Android 使用 Greendao 操作 db sqlite(2)-- 封装DaoUtils类
本博客地址: wukong1688
本文原文地址:https://www.cnblogs.com/wukong1688/p/10705622.html
转载请著名出处!谢谢~~
[Android] Android 使用 Greendao 操作 db sqlite(1)-- 直接在MainActivity中调用的更多相关文章
- [Android] Android 使用 Greendao 操作 db sqlite(2)-- 封装DaoUtils类
继续接上文: Android 使用 Greendao 操作 db sqlite(1)-- 直接在MainActivity中调用 布局文件同上文一致,这里就不贴了. 一.封装DaoUtils类 User ...
- [Android] Android 使用 Greendao 操作 db sqlite
Android 使用 Greendao 操作 db sqlite GreenDAO是一个开源的安卓ORM框架,能够使SQLite数据库的开发再次变得有趣.它减轻开发人员处理低级数据库需求,同时节省开发 ...
- 如何制作Jar包并在android中调用jar包
android制作jar包: 新建android工程,然后右击,点击导出,选择导出类型为Java下的JAR file,在java file specification 中不要选择androidmani ...
- [转]DllMain中不当操作导致死锁问题的分析——DllMain中要谨慎写代码(完结篇)
在CSDN中发现这篇文章,讲解的比较详细,所以在这里备份一个.原文链接:http://blog.csdn.net/breaksoftware/article/details/8167641 DllMa ...
- [Xcode 实际操作]九、实用进阶-(6)在Swift文件中调用Object-C的类和方法
目录:[Swift]Xcode实际操作 本文将演示在Swift文件中调用Object-C的类和方法. 在项目文件夹[DemoApp]上点击鼠标右键 ->[New File]创建一个Object- ...
- Android GreenDao操作外部DB数据库文件
1.背景 所谓外部数据库文件此处指的就是一个在外部单独创建的db文件,假设有这么一个场景,我们项目中有一些本地数据,不需要接口去获取的(不需要进行网络操作),写死的数据,比如全国各个省各个市的一些基本 ...
- Android数据库框架——GreenDao轻量级的对象关系映射框架,永久告别sqlite
Android数据库框架--GreenDao轻量级的对象关系映射框架,永久告别sqlite 前不久,我在写了ORMLite这个框架的博文 Android数据库框架--ORMLite轻量级的对象关系映射 ...
- android中的数据库操作(SQLite)
android中的数据库操作 android中的应用开发很难避免不去使用数据库,这次就和大家聊聊android中的数据库操作. 一.android内的数据库的基础知识介绍 1.用了什么数据库 an ...
- Android ORM——初识greenDAO 3及使用greenDAO 3前应该掌握的一些知识点(一)
引言 总所周知,SQLite--内嵌于Android中一个占用内存极小的关系型,作为我们Android存储领域中重要的一员 ,或多或少都曾接触到数据库.即使Android系统中提供了很多操作SQLit ...
随机推荐
- 【刷题】LOJ 556 「Antileaf's Round」咱们去烧菜吧
题目描述 你有 \(m\) 种物品,第 \(i\) 种物品的大小为 \(a_i\) ,数量为 \(b_i\)( \(b_i=0\) 表示有无限个). 你还有 \(n\) 个背包,体积分别为 \(1 ...
- Hdoj 1232.畅通工程 题解
Problem Description 某省调查城镇交通状况,得到现有城镇道路统计表,表中列出了每条道路直接连通的城镇.省政府"畅通工程"的目标是使全省任何两个城镇间都可以实现交通 ...
- 【arc071f】Infinite Sequence(动态规划)
[arc071f]Infinite Sequence(动态规划) 题面 atcoder 洛谷 题解 不难发现如果两个不为\(1\)的数连在一起,那么后面所有数都必须相等. 设\(f[i]\)表示\([ ...
- sql语句循环截取字符串
测试环境 : mssql2016 express 需求 : 拆分字符串执行insert 思路 : 在循环中截取分隔符之间的字符串.起止点位置计算 起点从0开始startIndex,查找第一个分隔 ...
- 136.137.260. Single Number && 位运算
136. Single Number 意思就是给你一堆数,每个数都出现了两次,只有一个数只出现了一次,找出这个数 位运算(和c艹一样) &:按位与 |:按位或 ^:异或(一样为0,不一样为1) ...
- [2017-7-27]Android Learning Day5
总结篇! 吭哧吭哧了三天,最近不断研究<第一行代码:第二版>170多页的那个新闻实践项目,虽然也没有用到数据库和一些Web爬虫的知识,新闻数据都是随机生成的字符串...... 但还是很开心 ...
- HDU--1540 Tunnel Warfare(线段树区间更新)
题目链接:1540 Tunnel Warfare 以为单组输入 这个题多组输入 结构体记录每个区间左边和右边的连续区间 ms记录最大 在查询操作时: 1.这个点即将查询到右区间 看这个点 x 是否存在 ...
- A1113. Integer Set Partition
Given a set of N (> 1) positive integers, you are supposed to partition them into two disjoint se ...
- A1072. Gas Station
A gas station has to be built at such a location that the minimum distance between the station and a ...
- Django(十一)请求生命周期之响应内容(请求/响应 头/体)
https://www.cnblogs.com/renpingsheng/p/7534897.html Django请求生命周期之响应内容 http提交数据的方式有"post",& ...