![當(dāng)外部應(yīng)用要對ContentProvider中的數(shù)據(jù)進行操作的時候_第1頁](http://file3.renrendoc.com/fileroot_temp3/2022-1/8/2e3a6fcf-fa1e-49ba-bdf3-d0baeec5c2ad/2e3a6fcf-fa1e-49ba-bdf3-d0baeec5c2ad1.gif)
![當(dāng)外部應(yīng)用要對ContentProvider中的數(shù)據(jù)進行操作的時候_第2頁](http://file3.renrendoc.com/fileroot_temp3/2022-1/8/2e3a6fcf-fa1e-49ba-bdf3-d0baeec5c2ad/2e3a6fcf-fa1e-49ba-bdf3-d0baeec5c2ad2.gif)
![當(dāng)外部應(yīng)用要對ContentProvider中的數(shù)據(jù)進行操作的時候_第3頁](http://file3.renrendoc.com/fileroot_temp3/2022-1/8/2e3a6fcf-fa1e-49ba-bdf3-d0baeec5c2ad/2e3a6fcf-fa1e-49ba-bdf3-d0baeec5c2ad3.gif)
![當(dāng)外部應(yīng)用要對ContentProvider中的數(shù)據(jù)進行操作的時候_第4頁](http://file3.renrendoc.com/fileroot_temp3/2022-1/8/2e3a6fcf-fa1e-49ba-bdf3-d0baeec5c2ad/2e3a6fcf-fa1e-49ba-bdf3-d0baeec5c2ad4.gif)
![當(dāng)外部應(yīng)用要對ContentProvider中的數(shù)據(jù)進行操作的時候_第5頁](http://file3.renrendoc.com/fileroot_temp3/2022-1/8/2e3a6fcf-fa1e-49ba-bdf3-d0baeec5c2ad/2e3a6fcf-fa1e-49ba-bdf3-d0baeec5c2ad5.gif)
下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認(rèn)領(lǐng)
文檔簡介
1、當(dāng)外部應(yīng)用要對ContentProvider中的數(shù)據(jù)進行操作的時候,可以使用ContentResolver類來完成,要獲取ContentResolver對象,可以使用activity的getContentResolver方法。 contentResolver類提供了與contentProvider相同簽名的四個方法public Uri insert(URI uri,ContentValues values); 這個方法用于添加數(shù)據(jù)public int delete(Uri uri,String selection,String selectionArgs) 這個方法用于刪
2、除數(shù)據(jù)public int update(Uri uri,ContentValues values,String selection,Stringp selectionArgs) 更新方法 下面用查詢方法詳細(xì)舉例 public class PersonProvider extends ContentProvider private static final String TAG = "PersonContentProvider" DBOpenHelper dbHelpe
3、r; private static final int PERSONLIST = 1; private static final int PERSON = 2; private static UriMatcher matcher; static matcher = new UriMatcher(UriMatch
4、er.NO_MATCH); matcher.addURI("vider.PersonProvider", "person", PERSONLIST); matcher.addURI("vider.PersonProvider", "person/#", PERSON);
5、160; Override public String getType(Uri uri) switch (matcher.match(uri) case PERSONLIST:/獲取所有記錄 就是這樣規(guī)定的 多條記錄返回這個
6、 return "vnd.android.cursor.dir/personprovider.person" case PERSON:/獲取單條記錄 單條記錄返回那個 return "vnd.android.cursor.
7、item/personprovider.person" default: throw new IllegalArgumentException("Uri IllegalArgument:"+ uri);
8、60; Override public boolean onCreate() dbHelper = new DBOpenHelper(this.getContext(); return true; Override
9、0; public Cursor query(Uri uri, String projection, String selection, String selectionArgs, String sortOrder) /獲取數(shù)據(jù)庫操作的類 SQLiteDatabase db = dbHelper.getReadableDatabase(); /聲明一個游標(biāo)
10、 Cursor cursor = null; switch (matcher.match(uri) case PERSONLIST:/獲取所有記錄 /cursor = db.query("pe
11、rson", projection, selection, selectionArgs, null, null, sortOrder); cursor = db.rawQuery("select * from person ", null); break;&
12、#160; case PERSON:/獲取單條記錄 long personid = ContentUris.parseId(uri); String where = selecti
13、on!=null && !"".equals(selection.trim() ? selection+ " and personid="+ personid : "personid="+ personid; cursor = db.query("person", projection, where, selectionArgs, null, n
14、ull, sortOrder); break; default: /如果什么都沒有找到,就拋出一個異常。 throw new IllegalArgumentException("Uri IllegalArgument:"+ uri);
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 物聯(lián)網(wǎng)時代的網(wǎng)絡(luò)安全技術(shù)及管理策略
- 3 桂花雨(說課稿)-2024-2025學(xué)年統(tǒng)編版語文五年級上冊
- 2023九年級數(shù)學(xué)上冊 第2章 一元二次方程2.2 一元二次方程的解法2.2.1 配方法第3課時 用配方法解二次項系數(shù)不為1的一元二次方程說課稿 (新版)湘教版
- Unit 6 Food Lesson 1(說課稿)-2024-2025學(xué)年人教精通版(2024)英語三年級上冊001
- 2025房地產(chǎn)委托合同書范本
- 2023九年級數(shù)學(xué)上冊 第二十四章 圓24.2 點和圓、直線和圓的位置關(guān)系24.2.2 直線和圓的位置關(guān)系第3課時 切線長定理說課稿(新版)新人教版001
- 2《我愛我們的祖國》說課稿-2024-2025學(xué)年統(tǒng)編版語文一年級上冊
- Unit1 Making friends Part C Make a mind map of making friends(說課稿)-2024-2025學(xué)年人教PEP版(2024)英語三年級上冊
- 2《我是什么》(說課稿)2024-2025學(xué)年二年級上冊語文統(tǒng)編版
- 2025關(guān)于招標(biāo)合同的報告
- 構(gòu)建綠色低碳的城市生態(tài)系統(tǒng)
- 春節(jié)習(xí)俗中的傳統(tǒng)節(jié)日服飾與裝扮
- 兒童編程課件
- (完整word版)英語四級單詞大全
- 武裝押運操作規(guī)程完整
- 混合動力汽車構(gòu)造與檢修(高職新能源汽車專業(yè))PPT完整全套教學(xué)課件
- 小學(xué)體育《運動前后的飲食衛(wèi)生》課件
- 薪酬專員崗位月度KPI績效考核表
- 技能大賽題庫(空分)
- 污水處理廠設(shè)備的操作規(guī)程(完整版)
- GB/T 28419-2012風(fēng)沙源區(qū)草原沙化遙感監(jiān)測技術(shù)導(dǎo)則
評論
0/150
提交評論