内容提供商
我创建了扩展 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?
}
我的问题是如何调用 insert() 来添加数据?
i had created class that extends contentprovider.
I had override the 6 functions
@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?
}
my question is how to call the insert() to add data?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过 getContentResolver() 获取 ContentResolver 实例 插入方法。
更新 这是最好的教程
Obtain ContentResolver instance via getContentResolver() insert method.
UPDATE That's the best tutorial