21 Days of learning Android development Tutorials SQLite paging Read _android

Source: Internet
Author: User
Tags sqlite create database

Android contains sqlite that are commonly used in embedded systems, eliminating the effort of developers to transplant their own installations. SQLite supports most SQL92 standards, and many of the most commonly used SQL commands can be used on SQLite, and Android offers a number of customized ways to simplify operations on SQLite databases. However, a program with Cross-platform requirements recommends using standard SQL statements, which can easily be ported across multiple platforms.
This article explains the basic usage of sqlite, such as: Creating a database, querying a datasheet with SQL commands, inserting data, shutting down a database, and using the GridView to implement a page bar (about the use of the GridView) for paging data.
The Pagebuttons.xml source code for the page bar is as follows:

<?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>

Main.xml source code is as follows:

<?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= "CREATE DATABASE" ></Button> <button android:layout_height= "Wrap_content" Android:layout_ Width= "Fill_parent" android:text= "inserts a string of experimental data" android:id= "@+id/btninsertrec" ></Button> <button android: layout_height= "Wrap_content" android:id= "@+id/btnclose" android:text= "Close Database" android:layout_width= "Fill_parent" &G t;</button> <edittext android:text= "@+id/edittext01" android:id= "@+id/edittext01" Android:layout_widt H= "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>

This program source code is as follows:

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; The public class Testsqlite extends activity {/** called the ' when ' is the ' The activity ' is a-a-created, btncreatedb 
  Insert, btnclose; 
  EditText edtsql;//Display paging data sqlitedatabase db; int id;//The ID accumulation mark when adding records, the total number of data per page is private static final String table_name = "Stu" when the global static final int pagesize=10;//paging is required 
  ; 
  Private static final String ID = "id"; 
   
  Private static final String name = "Name"; Simpleadapter sapageid;//page-Bar Adapter ArrayList 

The above is the entire content of this article, I hope to help you learn.

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.