[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 ...
随机推荐
- 【BZOJ5212】[ZJOI2018]历史(Link-Cut Tree)
[BZOJ5212][ZJOI2018]历史(Link-Cut Tree) 题面 洛谷 BZOJ 题解 显然实际上就是给定了一棵树和每个点被\(access\)的次数,求解轻重链切换的最大次数. 先考 ...
- Hadoop集群的构建和安装
1.安装Java $ yum install -y java-1.8.0-openjdk java-1.8.0-openjdk-devel 上述命令默认安装位置/usr/lib/jvm/java-1. ...
- VSCode创建自定义代码段
上一篇:PyCharm创建自定义代码段(JetBrains系列通用) 设置方法 很简单,快速过一下,F1,然后输入snippets 然后选择对应语言 Python案例 内容和使用: { // pref ...
- Typescript学习笔记(二)枚举
跟随handbook的脚步,详细介绍一下枚举. enum Direction { Up = 1, Down, Left, Right } 一个枚举类型可以包含零个或多个枚举成员,每个枚举成员可以是一个 ...
- Building real-time dashboard applications with Apache Flink, Elasticsearch, and Kibana
https://www.elastic.co/cn/blog/building-real-time-dashboard-applications-with-apache-flink-elasticse ...
- cf 990G - GCD Counting
题意 #include<bits/stdc++.h> #define t 200000 #define MAXN 200100 using namespace std; int n; in ...
- CF747F Igor and Interesting Numbers
我佛了,这CF居然没有官方题解. 题意:给定k,t,求第k小的16进制数,满足每个数码的出现次数不超过t. 解: 每个数都有个出现次数限制,搞不倒.一开始想到了排序hash数位DP,不过写了写觉得不胜 ...
- 关于字符编码,你所需要知道的(ASCII,Unicode,Utf-8,GB2312…)
字符编码的问题看似很小,经常被技术人员忽视,但是很容易导致一些莫名其妙的问题.这里总结了一下字符编码的一些普及性的知识,希望对大家有所帮助. 还是得从ASCII码说起 说到字符编码,不得不说ASCII ...
- spring 的 transactionManager 事务管理器 配置
转: 事务的传播特<tx:advice id="txadvice" transaction-manager="transactionManager"> ...
- C++基础知识--DAY3
今天我们开始进入封装类的地方 Encapsulation(封装) (1) C struct数据封装 当单一变量无法完成描述需求的时候,结构体类型解决了这一问题,可以将多个类型打包成一体,形成新的类型 ...