In general, Android itself contains sqlite that are commonly used in embedded systems, which eliminates 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 is recommended to use standard SQL statements, which can easily be ported across multiple platforms.
First, we will post the results of the program running:
This example program mainly 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>
</RelativeLayout>
The source code for the
Main.xml 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= "Insert a string of experimental data" android:id= "@+id/btninsertrec" ></Button> <button android:layout_height= "Wrap_content" android:id= "@+id/btnclose" android:text= "closes the database" 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>
Java 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
Interested readers can test this example code, hope to be able to carry on the development of Android project for some reference role.