Piglet's Android starter Road Day 7 Part 3

Source: Internet
Author: User

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





Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.