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 ...
随机推荐
- 【bzoj3668】[Noi2014]起床困难综合症 贪心
原文地址:http://www.cnblogs.com/GXZlegend/p/6797090.html 题目描述 21 世纪,许多人得了一种奇怪的病:起床困难综合症,其临床表现为:起床难,起床后精神 ...
- P4305 [JLOI2011]不重复数字
题目描述 给出N个数,要求把其中重复的去掉,只保留第一次出现的数. 例如,给出的数为1 2 18 3 3 19 2 3 6 5 4,其中2和3有重复,去除后的结果为1 2 18 3 19 6 5 4. ...
- [bzoj] 3263 陌上花开 洛谷 P3810 三维偏序|| CDQ分治 && CDQ分治讲解
原题 定义一个点比另一个点大为当且仅当这个点的三个值分别大于等于另一个点的三个值.每比一个点大就为加一等级,求每个等级的点的数量. 显然的三维偏序问题,CDQ的板子题. CDQ分治: CDQ分治是一种 ...
- linux命令Netstat
1.需求 了解Netstat命令 2.简介 命令用于显示各种网络相关信息,如网络连接,路由表,接口状态 (Interface Statistics),masquerade 连接,多播成员 (Multi ...
- bzoj1264 [AHOI2006]基因匹配Match 树状数组+lcs
1264: [AHOI2006]基因匹配Match Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1255 Solved: 835[Submit][ ...
- Math对象常用方法
1.Math.ceil(x) 返回x的向上取整. var a=Math.ceil(9.1); var b=Math.ceil(-9.1) console.log(a); console.log(b); ...
- MyEclipse内安装与使用SVN
安装教程 http://blog.csdn.net/u014756827/article/details/52288161 使用教程 http://www.cnblogs.com/keyi/p/594 ...
- HDU 4649 Professor Tian (概率DP)
Professor Tian Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)To ...
- BZOJ1179_APIO2009_抢掠计划_C++
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1179 一道用 Tarjan 缩点+SPFA 最长路的题(Tarjan 算法:http://ww ...
- RadioGroup和RadioButton(单选框)
1.布局文件 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:t ...