WEB开发网
开发学院手机开发Android 开发 Android本地的Content Provider 阅读

Android本地的Content Provider

 2010-09-27 01:53:00 来源:WEB开发网   
核心提示:// Let the activity manage the cursor lifecycle.startManagingCursor(cursor);// Use the convenience properties to get the index of the columnsint nameIdx = curso

// Let the activity manage the cursor lifecycle.

startManagingCursor(cursor);

// Use the convenience properties to get the index of the columns

int nameIdx = cursor.getColumnIndexOrThrow(People.NAME);

int phoneIdx = cursor. getColumnIndexOrThrow(People.NUMBER);

String[] result = new String[cursor.getCount()];

if (cursor.moveToFirst())

do {

// Extract the name.

String name = cursor.getString(nameIdx);

// Extract the phone number.

String phone = cursor.getString(phoneIdx);

result[cursor.getPosition()] = name + “ (“ + phone + “)”;

} while(cursor.moveToNext());

为了运行这个代码片段,你需要给程序添加READ_CONTACTS权限。

和查询联系人数据库一样,你还可以使用这个Content Provider来修改、删除或插入联系人记录。

上一页  1 2 

Tags:Android 本地 Content

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