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

Android 模拟器操作演练

 2010-02-20 17:15:00 来源:WEB开发网   
核心提示:catch (Exception e) { Log.e("ERROR", e.toString()); return; }try { db.execSQL("drop table "+ TABLE_NAME); }catch (Exception e) { Log.e("

catch (Exception e) { Log.e("ERROR", e.toString()); return; }

try { db.execSQL("drop table "+ TABLE_NAME); }

catch (Exception e) { Log.e("ERROR", e.toString()); }

db.execSQL("CREATE TABLE " + TABLE_NAME + " (" + "stud_no" + " TEXT,"

+ "stud_name" + " TEXT" + ");");

String sql_1 = "insert into "+ TABLE_NAME +

" (stud_no, stud_name) values('S101', 'Lily');";

String sql_2 = "insert into " + TABLE_NAME +

" (stud_no, stud_name) values('S102', 'Linda');";

String sql_3 = "insert into " + TABLE_NAME +

" (stud_no, stud_name) values('S103', 'Bruce');";

try { db.execSQL(sql_1); db.execSQL(sql_2); db.execSQL(sql_3); }

catch (SQLException e) { Log.e("ERROR", e.toString()); return; }

}

public Cursor query(String[] projection, String selection, String[] selectionArgs,

String sortOrder) {

Cursor cur = db.query(TABLE_NAME, projection, null, null, null, null, null);

return cur;

}

public void close(){ db.close(); }

}

这种用法属于非嫡系的用法:在ac01.java程式码里,其指令:

DataProvider dp = new DataProvider(this);

明确指定由DataProvider物件来提供服务。反之,嫡系用法则是透过意图(Intent)来请Android代为配对,进而找出适当的ContentProvider物件来为aco1物件提供服务。

2.2 嫡系SQLite的范例

刚才的范例里,我们直接使用DataProvider类别的介面来与SQLite沟通。本节的范例,将替DataProvider配上ContentProvider介面,让ac01物件能透过ContentProvider新介面来沟通。此范例也是从SQLite资料库读取3笔资料;请仔细看看其程式码的微妙差异:

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

package com.misoo.pkrr;

import java.util.ArrayList;

import java.util.HashMap;

import java.util.Map;

import android.app.ListActivity;

import android.content.Intent;

上一页  1 2 3 4 5 6 7  下一页

Tags:Android 模拟器 操作

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