Android 使用SQLite本地数据库
参考:http://blog.csdn.net/jianghuiquan/article/details/8569252
在Android平台上,集成了一个嵌入式关系型数据库—SQLite。以SQLite是一款轻型数据库:SQLite3支持 NULL、INTEGER、REAL(浮点数字)、TEXT(字符串文本)和BLOB(二进制对象)数据类型,虽然它支持的类型只有五种,但实际上sqlite3也接受varchar(n)、char(n)、decimal(p,s) 等数据类型,只不过在运算或保存时会转成对应的五种数据类型。
SQLite可以解析大部分标准SQL语句。
一、设计界面
1、布局文件
打开activity_main.xml文件。
输入以下代码:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#EFEFEF"> <TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/prompt"
android:textColor="@drawable/black" /> <EditText
android:id="@+id/editbook"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="@drawable/black" /> <TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="作者:"
android:textColor="@drawable/black" /> <EditText
android:id="@+id/editauthor"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="@drawable/black" /> <TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="出版社:"
android:textColor="@drawable/black" /> <EditText
android:id="@+id/editpublisher"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="@drawable/black" /> <ListView
android:id="@+id/listview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/black" /> </LinearLayout>
2、自定义列表文件
打开list.xml文件。
输入以下代码:
<?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"> <CheckedTextView android:id="@+id/textbookname"
android:layout_width="wrap_content"
android:layout_height="wrap_content" /> <ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/list_drive1" />
<CheckedTextView android:id="@+id/textauthor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/> <ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/list_drive1" /> <CheckedTextView android:id="@+id/textpublisher"
android:layout_width="wrap_content"
android:layout_height="wrap_content" /> </LinearLayout>
color.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<drawable name="black">#000000</drawable>
<drawable name="list_drive">#00000FFF</drawable>
<drawable name="white">#FFFFFFFF</drawable>
<drawable name="gray">#EFEFEF</drawable>
</resources>
string.xml
<resources>
<string name="app_name">My</string> <string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
<string name="prompt">书名:(请使用菜单:完成新增、修改、查询、刪除记录)</string>
<string name="addrec">新增</string>
<string name="editrec">修改</string>
<string name="queryrec">查询</string>
<string name="delrec">刪除</string>
</resources>
Android 使用SQLite本地数据库的更多相关文章
- Android应用查看本地数据库
使用Android Studio 视图==>工具窗口 == >Device File Explorer ==> 文件在 data/data目录下,你的应用程序报名,右键save as ...
- Android版本更新之本地数据库更新
最近上架了一个算法学习类APP,在更新应用版本时,发现数据库依旧没有更新,还是上一个版本的数据内容,遂把这方面的内容记录下来. PS:本人处女作APP <算法之家> 可以在豌豆荚.360手 ...
- Xamarin android使用Sqlite做本地存储数据库
android使用Sqlite做本地存储非常常见(打个比方就像是浏览器要做本地存储使用LocalStorage,貌似不是很恰当,大概就是这个意思). SQLite 是一个软件库,实现了自给自足的.无服 ...
- [转载]Unity3D 游戏引擎之使用C#语言建立本地数据库(SQLITE)
以前在开发中一直使用IOS源生的数据库,通过传递消息的形式在与Unity3D中进行交互.本文我在详细说说如何使用C#语言来在MAC 操作系统下创建Unity本地数据库,我是C#控哇咔咔--- 首先你需 ...
- Xamarin.Forms 使用本地数据库之 SQLite
前言 Xamarin.Forms支持使用SQLite数据库引擎.本文介绍了Xamarin.Forms应用程序如何读取和写入数据到使用SQLite.Net的本地SQLite数据库. 在Xamarin.F ...
- Android实现SQLite数据库的增、删、改、查的操作
核心代码DAO类 package com.examp.use_SQLite.dao; import java.util.ArrayList; import java.util.List; import ...
- Xamarin.Android 使用 SQLiteOpenHelper 进行数据库操作
一.前言 在手机中进行网络连接不仅是耗时也是耗电的,而耗电却是致命的.所以我们就需要数据库帮助我们存储离线数据,以便在用户未使用网络的情况下也可以能够使用应用的部分功能,而在需要网络连接的功能上采用提 ...
- Android本地数据存储之SQLite关系型数据库 ——SQLiteDatabase
数据库的创建,获取,执行sql语句: 框架搭建:dao 思考: 1.数据库保存在哪里? 2.如何创建数据库?如何创建表? 3.如何更新数据库?如何更改表的列数据? 4.如何获取数据库? 5.如何修改数 ...
- Android中SQLite数据库小计
2016-03-16 Android数据库支持 本文节选并翻译<Enterprise Android - Programing Android Database Applications for ...
随机推荐
- reinterpret_cast and const_cast
reinterpret_cast reinterpret意为“重新解释” reinterpret_cast是C++中与C风格类型转换最接近的类型转换运算符.它让程序员能够将一种对象类型转换为另一种,不 ...
- HDU 3033 组合背包变形 I love sneakers!
I love sneakers! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- ASP.NET——视频总结
ASP.NET的视频很早就看完了,但一直还没顾上总结.虽然在备战软考,学习任务很重,但是阶段的总结还是不要推太久了,不然也就起不到总结的效果了.在看视频之前,虽然已经做过了新闻发布系统,但是对B/S一 ...
- Nginx和Squid配合搭建的Web服务器前端系统
这个架构是目前我个人觉得比较稳妥并且最方便的架构,易于多数人接受: 前端的lvs和squid,按照安装方法,把epoll打开,配置文件照搬,基本上问题不多. 这个架构和app_squid架构的区别,也 ...
- [bzoj3813] 奇数国 [线段树+欧拉函数]
题面 传送门 思路 这题目是真的难读......阅读理解题啊...... 但是理解了以后就发现,题目等价于: 给你一个区间,支持单点修改,以及查询一段区间的乘积的欧拉函数值,这个答案对19961993 ...
- hust 1605 bfs
思路:直接用优先队列优化bfs. #include<map> #include<queue> #include<vector> #include<cmath& ...
- Topcoder SRM 602 div1题解
打卡- Easy(250pts): 题目大意:rating2200及以上和2200以下的颜色是不一样的(我就是属于那个颜色比较菜的),有个人初始rating为X,然后每一场比赛他的rating如果增加 ...
- DNS 资源记录解释
;SOA授权的开始;;SOA或授权的开始记录用来表示区域的启动;每个区域必须只有一个SOA记录;从名字服务器,在不能和主服务器通信的情况下,将提供12小时DNS服务, 在指定的时间后停止为那个区域提供 ...
- 动态符号链接的细节 与 linux程序的加载过程
转: http://hi.baidu.com/clivestudio/item/4341015363058d3d32e0a952 值得玩味的一篇分析程序链接.装载.动态链接细节的好文档 导读: by ...
- 用户空间缺页异常pte_handle_fault()分析--(下)--写时复制【转】
转自:http://blog.csdn.net/vanbreaker/article/details/7955713 版权声明:本文为博主原创文章,未经博主允许不得转载. 在pte_handle_fa ...