2011-05-11 185 views
0

我已經創建了擴展contentprovider的類。 我不得不重寫6個功能內容提供者

@override 
public Uri insert(Uri uri, ContentValues initialvalues) { 

    ContentValues values; 
    if(initialvalues != null){ 
     values = new ContentValues(initialvalues); 
    }else{ 
     values = new ContentValues(); 
    } 
    SQLiteDatabase mDb = mDbHelper.getWritableDatabase(); 
    long rowId = mDb.insert(DatabaseHelper.TABLE_PROGRAM, null, values); 
    if(rowId > 0){ 
     Uri programUri = ContentUris.withAppendedId(null, rowId); 
     getContext().getContentResolver().notifyChange(programUri, null); 
     return programUri; 
    } 
    throw new IllegalArgumentException("Failed to insert row into " + uri); 
} 

private void createdata(){ 
    String a = "a", b = "b", c = "c", d= "d"; 
    //how i going to call the content provider to let me to add in data? 
} 

我的問題是如何調用插入()添加數據?

回答

1

通過getContentResolver()insert方法獲取ContentResolver實例。

UPDATEThat's the best tutorial

+0

可以給我一些示例代碼? – newbie 2011-05-11 16:12:53

+0

從代碼,我無法找到內容提供商部分。 – newbie 2011-05-12 02:13:07