21天学习android开发教程之SQLite分页读取

2019-12-10 19:08:43王旭
21天学习android开发教程之SQLite分页读取,Android包含了常用于嵌入式系统的SQLite,免去了开发者自己移植安装的功夫,感兴趣的朋友可以参考一下  

Android包含了常用于嵌入式系统的SQLite,免去了开发者自己移植安装的功夫。SQLite 支持多数 SQL92 标准,很多常用的SQL命令都能在SQLite上面使用,除此之外Android还提供了一系列自定义的方法去简化对SQLite数据库的操作。不过有跨平台需求的程序就建议使用标准的SQL语句,毕竟这样容易在多个平台之间移植。
本文主要讲解了SQLite的基本用法,如:创建数据库,使用SQL命令查询数据表、插入数据,关闭数据库,以及使用GridView实现了一个分页栏(关于GridView的用法),用于把数据分页显示。
分页栏的pagebuttons.xml的源码如下:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://www.easck.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> 

main.xml的源码如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://www.easck.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="创建数据库"></Button>
    <Button android:layout_height="wrap_content"
        android:layout_width="fill_parent" android:text="插入一串实验数据" 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>