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 ...
随机推荐
- class内部处理
class A { public: int foo( ) { return val ; } static int staFun( ) { return staVal ; } static int st ...
- python3.6操作mysql
1.通过 pip 安装 pymysql 进入 cmd 输入 pip install pymysql 回车等待安装完成: 安装完成后出现如图相关信息,表示安装成功. 2.测试连接 import ...
- 【Linux】- 获取root权限命令
1:Redhat系统或者Fedora或者CentOs的Linux发行版,那么在Linux终端输入命令回车: su - root 这样就可以切换到root权限了 2:Ubuntu系统,在Linux终端输 ...
- Nagios 监控系统架设全攻略
Nagios 全名为(Nagios Ain’t Goona Insist on Saintood),最初项目名字是 NetSaint.它是一款免费的开源 IT 基础设施监控系统,其功能强大,灵活性强, ...
- $this和self、parent这三个关键词分别代表什么?在哪些场合下使用?
$this:当前对象 self: 当前类 parent: 当前类的父类 $this在当前类中使用,使用->调用属性和方法. self也在当前类中使用,不过需要使用::调用. 静态属性,不能在类里 ...
- Python中的单元测试模块Unittest快速入门
前言 为什么需要单元测试? 如果没有单元测试,我们会遇到这种情况:已有的健康运行的代码在经过改动之后,我们无法得知改动之后是否引入了Bug.如果有单元测试的话,只要单元测试全部通过,我们就可以保证没有 ...
- 第十五篇:jQuery
本篇内容 简介 使用 一. 简介 jQuery 是一个 JavaScript 库. jQuery 极大地简化了 JavaScript 编程. jQuery 很容易学习. jQuery 库可以通过一行简 ...
- 【bzoj4756】[Usaco2017 Jan]Promotion Counting 离散化+树状数组
原文地址:http://www.cnblogs.com/GXZlegend/p/6832263.html 题目描述 The cows have once again tried to form a s ...
- Avito Cool Challenge 2018 :E. Missing Numbers
E. Missing Numbers 题目链接:https://codeforces.com/contest/1081/problem/E 题意: 现在有n个数(n为偶数),但只给出a2,a4.... ...
- 转:ExecutorService
在Java5之后,并发线程这块发生了根本的变化,最重要的莫过于新的启动.调度.管理线程的一大堆API了.在Java5以后,通过 Executor来启动线程比用Thread的start()更好.在新特征 ...