Android實(shí)驗(yàn)四 Android應(yīng)用程序開(kāi)發(fā)

Android實(shí)驗(yàn)四 Android應(yīng)用程序開(kāi)發(fā)

ID:39346783

大?。?58.01 KB

頁(yè)數(shù):20頁(yè)

時(shí)間:2019-07-01

Android實(shí)驗(yàn)四 Android應(yīng)用程序開(kāi)發(fā)_第1頁(yè)
Android實(shí)驗(yàn)四 Android應(yīng)用程序開(kāi)發(fā)_第2頁(yè)
Android實(shí)驗(yàn)四 Android應(yīng)用程序開(kāi)發(fā)_第3頁(yè)
Android實(shí)驗(yàn)四 Android應(yīng)用程序開(kāi)發(fā)_第4頁(yè)
Android實(shí)驗(yàn)四 Android應(yīng)用程序開(kāi)發(fā)_第5頁(yè)
資源描述:

《Android實(shí)驗(yàn)四 Android應(yīng)用程序開(kāi)發(fā)》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫(kù)

1、計(jì)算機(jī)科學(xué)與技術(shù)系實(shí)驗(yàn)報(bào)告專(zhuān)業(yè)名稱(chēng)計(jì)算機(jī)科學(xué)與技術(shù)課程名稱(chēng)Android應(yīng)用程序開(kāi)發(fā)項(xiàng)目名稱(chēng)數(shù)據(jù)存儲(chǔ)與訪問(wèn)班級(jí)計(jì)科1班學(xué)號(hào)姓名同組人員無(wú)實(shí)驗(yàn)日期2016.9.2720一、實(shí)驗(yàn)?zāi)康呐c要求:1.1實(shí)驗(yàn)?zāi)康恼莆誗QLite存儲(chǔ)數(shù)據(jù)的方法,掌握ContentProvider的用法。1.2實(shí)驗(yàn)要求(1)練習(xí)使用SQLite數(shù)據(jù)庫(kù)的方式進(jìn)行數(shù)據(jù)存儲(chǔ)和訪問(wèn)。(2)練習(xí)使用ContentProvider訪問(wèn)其他應(yīng)用程序的數(shù)據(jù)。(3)完成實(shí)驗(yàn)報(bào)告。二、實(shí)驗(yàn)內(nèi)容2.1實(shí)驗(yàn)原理(1)數(shù)據(jù)存儲(chǔ)方式SharedPreferences、File存儲(chǔ)、SQLite數(shù)據(jù)庫(kù)(2)ContentProvider數(shù)據(jù)共享在

2、創(chuàng)建ContentProvider前,首先要實(shí)現(xiàn)底層的數(shù)據(jù)源,數(shù)據(jù)源包括數(shù)據(jù)庫(kù)、文件系統(tǒng)或網(wǎng)絡(luò)等,然后繼承ContentProvider類(lèi)中實(shí)現(xiàn)基本數(shù)據(jù)操作的接口函數(shù),包括添加、刪除、查找和更新等功能,調(diào)用者不能直接調(diào)用ContentProvider的接口函數(shù),而需要使用ContentResolver對(duì)象,通過(guò)URI間接調(diào)用ContentProvider,調(diào)用關(guān)系如圖:2.2實(shí)驗(yàn)過(guò)程及截圖(1)新建Android應(yīng)用程序項(xiàng)目SQLiteTest,創(chuàng)建SQLite數(shù)據(jù)庫(kù)和表,并實(shí)現(xiàn)數(shù)據(jù)庫(kù)數(shù)據(jù)讀取和存入操作。201)新建SQLiteTest項(xiàng)目2)代碼邏輯:MainActivity.jav

3、a文件packageedu.hfuu.sqlitetest;importandroid.app.Activity;importandroid.database.Cursor;importandroid.database.sqlite.SQLiteDatabase;importandroid.os.Bundle;importandroid.view.View;importandroid.widget.Button;importandroid.widget.EditText;importandroid.widget.Toast;publicclassMainActivityextendsA

4、ctivity{SQLiteDatabasesld,sdtest;Buttonbt_open,bt_close,bt_add,bt_delete,bt_update,bt_query;EditTextet_log,et_query;@OverrideprotectedvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);20bt_open=(Button)findViewById(R.id.Button01);bt_

5、close=(Button)findViewById(R.id.Button02);bt_add=(Button)findViewById(R.id.Button03);bt_delete=(Button)findViewById(R.id.Button04);bt_update=(Button)findViewById(R.id.Button05);bt_query=(Button)findViewById(R.id.Button06);et_log=(EditText)this.findViewById(R.id.EditText01);et_query=(EditText)thi

6、s.findViewById(R.id.EditText02);}//創(chuàng)建、打開(kāi)數(shù)據(jù)庫(kù)publicvoidcreateDatabase(Viewv){try{sdtest=openOrCreateDatabase("dbtest.db3",MODE_PRIVATE,null);sld=SQLiteDatabase.openOrCreateDatabase(this.getFilesDir().toString()+"/mydb.db3",null);appendMessage(et_log,"數(shù)據(jù)庫(kù)已經(jīng)成功打開(kāi)!");Stringsql="createtableifnotexistss

7、tudent(sidintegerprimarykeyautoincrement,snochar(5),"+"stunamevarchar(20),"+"sageinteger)";sld.execSQL(sql);appendMessage(et_log,"student已經(jīng)成功創(chuàng)建!");}catch(Exceptione){Toast.makeText(this,"數(shù)據(jù)庫(kù)錯(cuò)誤:"+e.toString(),Toast.LENGTH_SHO

當(dāng)前文檔最多預(yù)覽五頁(yè),下載文檔查看全文

此文檔下載收益歸作者所有

當(dāng)前文檔最多預(yù)覽五頁(yè),下載文檔查看全文
溫馨提示:
1. 部分包含數(shù)學(xué)公式或PPT動(dòng)畫(huà)的文件,查看預(yù)覽時(shí)可能會(huì)顯示錯(cuò)亂或異常,文件下載后無(wú)此問(wèn)題,請(qǐng)放心下載。
2. 本文檔由用戶(hù)上傳,版權(quán)歸屬用戶(hù),天天文庫(kù)負(fù)責(zé)整理代發(fā)布。如果您對(duì)本文檔版權(quán)有爭(zhēng)議請(qǐng)及時(shí)聯(lián)系客服。
3. 下載前請(qǐng)仔細(xì)閱讀文檔內(nèi)容,確認(rèn)文檔內(nèi)容符合您的需求后進(jìn)行下載,若出現(xiàn)內(nèi)容與標(biāo)題不符可向本站投訴處理。
4. 下載文檔時(shí)可能由于網(wǎng)絡(luò)波動(dòng)等原因無(wú)法下載或下載錯(cuò)誤,付費(fèi)完成后未能成功下載的用戶(hù)請(qǐng)聯(lián)系客服處理。