-
-
Save zinwalin/e62e26c231767170e14c5c83aab19e8d to your computer and use it in GitHub Desktop.
Revisions
-
dearsq revised this gist
Aug 17, 2018 . No changes.There are no files selected for viewing
-
dearsq revised this gist
Aug 10, 2018 . 1 changed file with 7 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ ## 基本概念 用法两种: 1. 使用现有的ContentProvider来读取和操作相应程序中的数据 2. 创建自己的内容提供器给我们的程序的数据提供外部访问接口 ## 创建自己的内容提供器 新建一个类用来集成 ContentProvider -
dearsq revised this gist
Aug 10, 2018 . 1 changed file with 60 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1 +1,60 @@ ## 基本概念 用法两种: 1. 使用现有的ContentProvider来读取和操作相应程序中的数据 2. 创建自己的内容提供器给我们的程序的数据提供外部访问接口 ## ContentResolver 使用方法 ContentResolver resolver = Context.getContentResolver(); resolver.insert //增 resolver.delete //删 resolver.update //改 resolver.query //查 参数为 内容URI : `content://com.example.app.provider/table1` 不过得先解析为 URI 对象: `Uri uri = Uri.parse("content://com.example.app.provider/table1")` 使用 内容URI 查询 table1 的内容: ``` Cursor cursor = getContentResolver().query( uri, projection, //指定列名 selection, //Where约束 selectionArgs, //Where占位符提供具体的值 sortOrder //指定查询结果的排序方式 ); ``` 通过移动游标位置,遍历 Cursor: ``` if (cursor != null){ while (cursor.moveToNext()) { String column1 = cursor.getString(cursor.getColumnIndex("column1")); int column2 = cursor.getInt(cursor.getColumnIndex("column2")); } cursor.close(); } ``` ## 操作实例 //增 ``` ContentValues values = new ContentValues(); values.put("column1", "text"); values.put("column2", 1); getContentResolver().insert(uri,values); // 增 ``` //改 ``` ContentValues values = new ContentValues(); values.put("column1", ""); getContentResolver().update(uri. values, "column1 = ? and column2 = ?" , new String[] {"text" , "1"}); //改 ``` //删 ``` getContentResolver().delete(uri, "column2 = ?", new String[] {"1"}); ``` -
dearsq created this gist
Aug 10, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ 1