Piglet's Android starter Road Day 7 Part 3
--sqlite database for Android data storage and access
---reprint please specify the Source: Coder-pig
Introduction to this section:
In the first two part we learned to use files and sharedpreference to save data, but in many cases
Files are not necessarily valid, such as multi-threaded concurrent access is relevant; The app handles complex data structures that can change, and so on!
Like the bank's saving and taking money! A database is needed for these situations! And Android also gives us a built-in
SQLite database support, SQLite is very delicate, not like oracle,mssql or MySQL need to install, start the service
to use; The SQLite database is just a file that is ideal for use on mobile devices! About the SQLite database
Create, delete, change, transaction, etc. please listen to the author's one by one, in addition, if you want to view the official examples can be viewed in the SDK
Simple/notepad Directory!
Learning Roadmap for this section:
Before studying this article, you need to download and install a SQLite graphical tool, because SQLite and MySQL are the same, are used
command-line, and we often need to look at the structure and content of the tables in the database, so we need to use graphical tools!
and this kind of tool has a lot of, specific oneself Baidu under! I like and suggest you use: SQLite expert!
The function is very powerful! Here is the version that I am using to download:sqliteexpert Download
Body:
Features of SQLite
Create a database and version management using Sqliteopenhelper
PS: When we want to call the Onupgrade () method It is only necessary to modify the version number in the constructor Method!
Implementing Operations Database Operations (SQLITEDATABASE and cursor)
SQLite Transaction (Transaction)
Save the picture to SQLite and read the picture in SQLite:
simplecursoradapter Binding Database Data
In the end there is an adapter simplecursoradapter (), although this is not commonly used, but this adapter is Android specifically for
Connection database and view, using this adapter makes it easy to display data from database tables in a ListView! Of course you
Other adapter adapters can be used!
Code example: Bind data in a database to a ListView by Simplecursoradapter
Run:
Core code:
This section refers to the code:
The code for the Database Operations section is a reference to the example code of the Dawn live teacher, which uploads his sample code directly: Reference Code Download
use of Simplecursoradapter: Reference Code Download