Android improves SQLite paging reading in Article 8

Source: Internet
Author: User

Android contains SQLite, which is commonly used in embedded systems, saving developers from porting and installing it themselves. SQLite supports most SQL92 standards, and many commonly used SQL commands can be used on SQLite. In addition, Android also provides a series of custom methods to simplify operations on the SQLite database. However, it is recommended that standard SQL statements be used for programs with cross-platform requirements. After all, it is easy to port between multiple platforms.

First paste the results of the program running in this article:

This article describes the basic usage of SQLite, such as creating a database, using SQL commands to query data tables, inserting data, and disabling a database, and use the GridView to implement a paging column (about the usage of the GridView), used to display data by page.

The source code of pagebuttons. xml on the page bar is as follows:

View plaincopy to clipboardprint?
<? Xml version = "1.0" encoding = "UTF-8"?>
<RelativeLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: layout_height = "wrap_content" android: paddingBottom = "4dip"
Android: layout_width = "fill_parent">
<TextView android: layout_width = "wrap_content"
Android: layout_below = "@ + id/ItemImage" android: layout_height = "wrap_content"
Android: text = "TextView01" android: layout_centerHorizontal = "true"
Android: id = "@ + id/ItemText">
</TextView>
</RelativeLayout>
<? Xml version = "1.0" encoding = "UTF-8"?>
<RelativeLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: layout_height = "wrap_content" android: paddingBottom = "4dip"
Android: layout_width = "fill_parent">
<TextView android: layout_width = "wrap_content"
Android: layout_below = "@ + id/ItemImage" android: layout_height = "wrap_content"
Android: text = "TextView01" android: layout_centerHorizontal = "true"
Android: id = "@ + id/ItemText">
</TextView>
</RelativeLayout>

The source code of main. xml is as follows:

 

View plaincopy to clipboardprint?
<? Xml version = "1.0" encoding = "UTF-8"?>
<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: orientation = "vertical" android: layout_width = "fill_parent"
Android: layout_height = "fill_parent">
<Button android: layout_height = "wrap_content"
Android: layout_width = "fill_parent" android: id = "@ + id/btnCreateDB"
Android: text = "creating a database"> </Button>
<Button android: layout_height = "wrap_content"
Android: layout_width = "fill_parent" android: text = "insert a series of experiment data"Android: id =" @ + id/btnInsertRec "> </Button>
<Button android: layout_height = "wrap_content" android: id = "@ + id/btnClose"
Android: text = "" android: layout_width = "fill_parent"> </Button>
<EditText android: text = "@ + id/EditText01" android: id = "@ + id/EditText01"
Android: layout_width = "fill_parent" android: layout_height = "256dip"> </EditText>
<GridView android: id = "@ + id/gridview" android: layout_width = "fill_parent"
Android: layout_height = "32dip" android: numColumns = "auto_fit"
Android: columnWidth = "40dip"> </GridView>
</LinearLayout>
<? Xml version = "1.0" encoding = "UTF-8"?>
<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: orientation = "vertical" android: layout_width = "fill_parent"
Android: layout_height = "fill_parent">
<Button android: layout_height = "wrap_content"
Android: layout_width = "fill_parent" android: id = "@ + id/btnCreateDB"
Android: text = "creating a database"> </Button>
<Button android: layout_height = "wrap_content"
Android: layout_width = "fill_parent" android: text = "insert a series of experiment data"Android: id =" @ + id/btnInsertRec "> </Button>
<Button android: layout_height = "wrap_content" android: id = "@ + id/btnClose"
Android: text = "" android: layout_width = "fill_parent"> </Button>
<EditText android: text = "@ + id/EditText01" android: id = "@ + id/EditText01"
Android: layout_width = "fill_parent" android: layout_height = "256dip"> </EditText>
<GridView android: id = "@ + id/gridview" android: layout_width = "fill_parent"
Android: layout_height = "32dip" android: numColumns = "auto_fit"
Android: columnWidth = "40dip"> </GridView>
</LinearLayout>
 

The program source code in this article is as follows:

View plaincopy to clipboardprint?
Package com. testSQLite;

Import java. util. ArrayList;
Import java. util. HashMap;
Import android. app. Activity;
Import android. database. Cursor;
Import android. database. SQLException;
Import android. database. sqlite. SQLiteDatabase;
Import android. OS. Bundle;
Import android. util. Log;
Import android. view. View;
Import android. widget. AdapterView;
Import android. widget. AdapterView. OnItemClickListener;
Import android. widget. Button;
Import android. widget. EditText;
Import android. widget. GridView;
Import android. widget. SimpleAdapter;

Public class testSQLite extends Activity {
/** Called when the activity is first created .*/
Button btnCreateDB, btnInsert, btnClose;
EditText edtSQL; // display paging data
SQLiteDatabase db;
Int id; // The id accumulation mark when the record is added. It must be global.
Static final int PageSize = 10; // The total number of data entries on each page.
Private static final String TABLE_NAME = "stu ";
Private static final String ID = "id ";
Private static final String NAME = "name ";

SimpleAdapter saPageID; // adapter in the paging bar
ArrayList <HashMap <String, String> lstPageID; // data source in the paging column, which is related to PageSize and total data count

@ Override

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.