2011-12-28 65 views

回答

0

//使用內容提供商你可以做到這一點 還有一些輔助方法,尤其是ContentUris.withAppendedId()和Uri.withAppendedPath(),這可以很容易地追加一個ID到一個URI。兩者都是靜態方法,返回帶有ID添加ID的Uri對象。因此,舉例來說,如果你在人們接觸的數據庫尋找創紀錄的2300,你可以按照以下方式構造查詢:

import android.provider.Contacts.People; 
import android.content.ContentUris; 
import android.net.Uri; 
import android.database.Cursor; 

// Use the ContentUris method to produce the base URI for the contact with _ID == 23. 
Uri myPerson = ContentUris.withAppendedId(People.CONTENT_URI, 23); 

// Alternatively, use the Uri method to produce the base URI. 
// It takes a string rather than an integer. 
Uri myPerson = Uri.withAppendedPath(People.CONTENT_URI, "23"); 

// Then query for this specific record: 
Cursor cur = managedQuery(myPerson, null, null, null, null); 

refer this