WEB开发网
开发学院手机开发Android 开发 Android 模拟器操作演练 阅读

Android 模拟器操作演练

 2010-02-20 17:15:00 来源:WEB开发网   
核心提示:PROJECTION = new String[] { "stud_no", "stud_name" };@Override protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInsta

PROJECTION = new String[] { "stud_no", "stud_name" };

@Override protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

DataProvider dp = new DataProvider(this);

Cursor cur = dp.query(PROJECTION, null, null, null);

ArrayList> coll

= new ArrayList>();

Map item;

cur.moveToFirst();

while(!cur.isAfterLast()) {

item = new HashMap();

item.put("c1", cur.getString(0) + ", " + cur.getString(1));

coll.add(item);

cur.moveToNext();

}

dp.close();

this.setListAdapter(new SimpleAdapter(this, coll,

android.R.layout.simple_list_item_1, new String[] { "c1" },

new int[] {android.R.id.text1}));

}

@Override

protected void onListItemClick(ListView l, View v, int position, long id) {

finish();

}}

指令:

DataProvider dp = new DataProvider(this);

这和一般类别之用法是一样的。 ac01物件指名要诞生一个DataProvider的物件。然后呼叫它,如下指令:

Cursor cur = dp.query(PROJECTION, null, null, null);

这要求SQLite从资料库查询出某些资料。详细的DataProvider.java程式码如下:

/* ----- DataProvider.java 程式码------*/

package com.misoo.pklx;

import android.content.Context;

import android.database.Cursor;

import android.database.SQLException;

import android.database.sqlite.SQLiteDatabase;

import android.util.Log;

public class DataProvider {

private static final String DATABASE_NAME = "StudDB";

private static final String TABLE_NAME = "Student";

private final int DB_MODE = Context.MODE_PRIVATE;

private SQLiteDatabase db=null;

public DataProvider(Context ctx) {

try { db = ctx.openOrCreateDatabase(DATABASE_NAME, DB_MODE, null); }

1 2 3 4 5 6  下一页

Tags:Android 模拟器 操作

编辑录入:coldstar [复制链接] [打 印]
赞助商链接