Android数据库 分页查询,Android之怎么使用SQLite数据库(增、删、改、查、分页等)以及ListView显示数据(转)...

由于刚接触android开发,故此想把学到的基础知识记录一下,以备查询,故此写的比较啰嗦:

步骤如下:

一、介绍:

此文主要是介绍怎么使用android自带的数据库SQLite,以及把后台的数据用ListView控件显示

二、新建一个android工程——DBSQLiteOperate

工程目录:

a4c26d1e5885305701be709a3d33442f.png

三、清单列表AndroidManifest.xml的配置为:

< ?xml version="1.0" encoding="utf-8"?>

< manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="com.example.dboperate"

android:versionCode="1"

android:versionName="1.0" >

android:icon="@drawable/ic_launcher"

android:label="@string/app_name" >

android:name=".DBSQLiteOperateActivity"

android:label="@string/app_name" >

android:targetPackage="com.example.dboperate"

android:label="Test for my app"/>

< /manifest>

四、main.xml配置清单:

< ?xml version="1.0" encoding="utf-8"?>

< LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="vertical" >

android:layout_height="wrap_content"

android:orientation="horizontal" >

android:id="@+id/name"

android:layout_width="100dip"

android:layout_height="wrap_content"

android:text="@string/name"

android:gravity="center"/>

android:id="@+id/phone"

android:layout_width="100dip"

android:layout_height="wrap_content"

android:text="@string/phone"

android:gravity="center"/>

android:id="@+id/amount"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="@string/amount"

android:gravity="center"/>

< /LinearLayout>

android:id="@+id/listView"

android:layout_width="fill_parent"

android:layout_height="fill_parent" >

< /LinearLayout>

五、item.xml配置清单:

< ?xml version="1.0" encoding="utf-8"?>

< LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="horizontal" >

android:id="@+id/name"

android:layout_width="100dip"

android:layout_height="wrap_content"

android:text="@string/name"

android:gravity="center"/>

android:id="@+id/phone"

android:layout_width="100dip"

android:layout_height="wrap_content"

android:text="@string/phone"

android:gravity="center"/>

android:id="@+id/amount"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="@string/amount"

android:gravity="center"/>

< /LinearLayout>

六、string.xml配置清单:

< ?xml version="1.0" encoding="utf-8"?>

< resources>

Hello World, DBSQLiteOperateActivity!

ExampleDBSQLiteOperate8

姓名

电话

存款

< /resources>

七、DBSQLiteOperateActivity.java Activity类的源码:

package com.example.dboperate;

import java.util.ArrayList;

import java.util.HashMap;

import java.util.List;

import java.util.Map;

import com.example.adapter.PersonAdapter;

import com.example.domain.Person;

import com.example.service.PersonService;

import android.app.Activity;

import android.database.Cursor;

import android.os.Bundle;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.AdapterView;

import android.widget.AdapterView.OnItemClickListener;

import android.widget.ListView;

import android.widget.SimpleAdapter;

import android.widget.SimpleCursorAdapter;

import android.widget.Toast;

public class DBSQLiteOperateActivity extends Activity {

ListView listView;

PersonService personService;

OnItemClickListener listViewListener;

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

listViewListener = new OnItemClickListener(){

@Override

public void onItemClick(AdapterView

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值