{"id":636,"date":"2013-05-27T10:36:29","date_gmt":"2013-05-27T10:36:29","guid":{"rendered":"http:\/\/hsiunien.sinaapp.com\/?p=636"},"modified":"2013-05-27T10:36:29","modified_gmt":"2013-05-27T10:36:29","slug":"android-%e5%85%b3%e4%ba%8e%e6%95%b0%e6%8d%ae%e5%ba%93%e8%ae%bf%e9%97%ae","status":"publish","type":"post","link":"https:\/\/blog.xiunian.wang\/?p=636","title":{"rendered":"Android \u5173\u4e8e\u6570\u636e\u5e93\u8bbf\u95ee"},"content":{"rendered":"<p>Android \u7528\u7684\u00a0\u6570\u636e\u5e93\u662fSqlite3\uff0c\u3002<\/p>\n<p>android \u64cd\u4f5c\u6570\u636e\u5e93\u548c\u6211\u4eec\u7528\u5176\u4ed6\u8bed\u8a00\u64cd\u4f5c\u6570\u636e\u5e93\u5dee\u4e0d\u591a\u3002<\/p>\n<p>\u9996\u5148\u53d6\u5f97\u6570\u636e\u5e93\u5bf9\u8c61<\/p>\n<p>SQLiteDatabase<br \/>\n<code><br \/>\ndb= SQLiteDatabase.openDatabase(MyApp.MAINACITVITY.getDatabasePath(\"\u6570\u636e\u5e93\u6587\u4ef6\u540d\").toString(),null,SQLiteDatabase.OPEN_READONLY);<\/code><br \/>\n\u7136\u540e\u901a\u8fc7db\u53d6\u5f97cursor\u5bf9\u8c61 \u8fd9\u4e2acursor\u76f8\u5f53\u4e8e\u6570\u636e\u96c6 dataset<br \/>\n<code><br \/>\nCursor cursor=db.rawQuery(\"select id,name,x,y from locationInfo \", null);<br \/>\nMainActivity.ccsuMapAPP.startManagingCursor(cursor);\/\/\u8fd9\u53e5\u8bdd\u8981\u8c03\u7528\u4e00\u6b21\u4f7f\u5f97cursor\u751f\u547d\u5468\u671f\u548cactivity\u540c\u6b65 \u4f46\u662f\u6700\u540e\u8981\u8bb0\u5f97\u8c03\u7528stopManagingCursor\uff08\uff09<br \/>\nwhile(cursor.moveToNext()){<br \/>\nLocationTag tag=new LocationTag(MainActivity.ccsuMapAPP,this);<br \/>\ntag.setBaseInfo(cursor.getInt(0), cursor.getString(1), cursor.getInt(2), cursor.getInt(3));<br \/>\ntags.add(tag);<br \/>\n}<br \/>\n<\/code><br \/>\n\u603b\u7ed3\u4e00\u4e0bActivity.startManagingCursor\u65b9\u6cd5\uff1a \u8f6c<br \/>\n\u6211\u4eec\u5c06\u83b7\u5f97\u7684Cursor\u5bf9\u8c61\u4ea4\u4e0eActivity \u6765\u7ba1\u7406\uff0c\u8fd9\u6837Cursor\u5bf9\u8c61\u7684\u751f\u547d\u5468\u671f\u4fbf\u80fd\u4e0e\u5f53\u524d\u7684Activity\u81ea\u52a8\u540c\u6b65\uff0c\u7701\u53bb\u4e86\u81ea\u5df1\u7ba1\u7406Cursor\u3002<\/p>\n<p>1.\u8fd9\u4e2a\u65b9\u6cd5\u4f7f\u7528\u7684\u524d\u63d0\u662f\uff1a\u6e38\u6807\u7ed3\u679c\u96c6\u91cc\u6709\u5f88\u591a\u7684\u6570\u636e\u8bb0\u5f55\u3002<br \/>\n\u6240\u4ee5\uff0c\u5728\u4f7f\u7528\u4e4b\u524d\uff0c\u5148\u5bf9Cursor\u662f\u5426\u4e3anull\u8fdb\u884c\u5224\u65ad\uff0c\u5982\u679cCursor != null\uff0c\u518d\u4f7f\u7528\u6b64\u65b9\u6cd5<\/p>\n<p>2.\u5982\u679c\u4f7f\u7528\u8fd9\u4e2a\u65b9\u6cd5\uff0c\u6700\u540e\u4e5f\u8981\u7528stopManagingCursor\uff08\uff09\u6765\u628a\u5b83\u505c\u6b62\u6389\uff0c\u4ee5\u514d\u51fa\u73b0\u9519\u8bef\u3002<\/p>\n<p>3.\u4f7f\u7528\u8fd9\u4e2a\u65b9\u6cd5\u7684\u76ee\u7684\u662f\u628a\u83b7\u53d6\u7684Cursor\u5bf9\u8c61\u4ea4\u7ed9Activity\u7ba1\u7406\uff0c\u8fd9\u6837Cursor\u7684\u751f\u547d\u5468\u671f\u4fbf\u80fd\u548cActivity\u81ea\u52a8\u540c\u6b65\uff0c<br \/>\n\u7701\u53bb\u81ea\u5df1\u624b\u52a8\u7ba1\u7406\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Android \u7528\u7684\u00a0\u6570\u636e\u5e93\u662fSqlite3\uff0c\u3002 android \u64cd\u4f5c\u6570\u636e\u5e93\u548c\u6211\u4eec\u7528\u5176\u4ed6\u8bed\u8a00\u64cd\u4f5c\u6570\u636e\u5e93\u5dee\u4e0d\u591a\u3002 \u9996\u5148\u53d6\u5f97\u6570\u636e\u5e93\u5bf9\u8c61 SQLiteDatabase db= SQLiteDatabase.openDatabase(MyApp.MAINACITVITY.getDatabasePath(&#8220;\u6570\u636e\u5e93\u6587\u4ef6\u540d&#8221;).toString(),null,SQLiteDatabase.OPEN_READONLY); \u7136\u540e\u901a\u8fc7db\u53d6\u5f97cursor\u5bf9\u8c61 \u8fd9\u4e2acursor\u76f8\u5f53\u4e8e\u6570\u636e\u96c6 dataset Cursor cursor=db.rawQuery(&#8220;select id,name,x,y from locationInfo &#8220;, null); MainActivity.ccsuMapAPP.startManagingCursor(cursor);\/\/\u8fd9\u53e5\u8bdd\u8981\u8c03\u7528\u4e00\u6b21\u4f7f\u5f97cursor\u751f\u547d\u5468\u671f\u548cactivity\u540c\u6b65 \u4f46\u662f\u6700\u540e\u8981\u8bb0\u5f97\u8c03\u7528stopManagingCursor\uff08\uff09 while(cursor.moveToNext()){ LocationTag tag=new LocationTag(MainActivity.ccsuMapAPP,this); tag.setBaseInfo(cursor.getInt(0), cursor.getString(1), cursor.getInt(2), cursor.getInt(3)); tags.add(tag); } \u603b\u7ed3\u4e00\u4e0bActivity.startManagingCursor\u65b9\u6cd5\uff1a \u8f6c \u6211\u4eec\u5c06\u83b7\u5f97\u7684Cursor\u5bf9\u8c61\u4ea4\u4e0eActivity \u6765\u7ba1\u7406\uff0c\u8fd9\u6837Cursor\u5bf9\u8c61\u7684\u751f\u547d\u5468\u671f\u4fbf\u80fd\u4e0e\u5f53\u524d\u7684Activity\u81ea\u52a8\u540c\u6b65\uff0c\u7701\u53bb\u4e86\u81ea\u5df1\u7ba1\u7406Cursor\u3002 1.\u8fd9\u4e2a\u65b9\u6cd5\u4f7f\u7528\u7684\u524d\u63d0\u662f\uff1a\u6e38\u6807\u7ed3\u679c\u96c6\u91cc\u6709\u5f88\u591a\u7684\u6570\u636e\u8bb0\u5f55\u3002 \u6240\u4ee5\uff0c\u5728\u4f7f\u7528\u4e4b\u524d\uff0c\u5148\u5bf9Cursor\u662f\u5426\u4e3anull\u8fdb\u884c\u5224\u65ad\uff0c\u5982\u679cCursor != null\uff0c\u518d\u4f7f\u7528\u6b64\u65b9\u6cd5 2.\u5982\u679c\u4f7f\u7528\u8fd9\u4e2a\u65b9\u6cd5\uff0c\u6700\u540e\u4e5f\u8981\u7528stopManagingCursor\uff08\uff09\u6765\u628a\u5b83\u505c\u6b62\u6389\uff0c\u4ee5\u514d\u51fa\u73b0\u9519\u8bef\u3002 3.\u4f7f\u7528\u8fd9\u4e2a\u65b9\u6cd5\u7684\u76ee\u7684\u662f\u628a\u83b7\u53d6\u7684Cursor\u5bf9\u8c61\u4ea4\u7ed9Activity\u7ba1\u7406\uff0c\u8fd9\u6837Cursor\u7684\u751f\u547d\u5468\u671f\u4fbf\u80fd\u548cActivity\u81ea\u52a8\u540c\u6b65\uff0c \u7701\u53bb\u81ea\u5df1\u624b\u52a8\u7ba1\u7406\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,8],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.xiunian.wang\/index.php?rest_route=\/wp\/v2\/posts\/636"}],"collection":[{"href":"https:\/\/blog.xiunian.wang\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.xiunian.wang\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.xiunian.wang\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.xiunian.wang\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=636"}],"version-history":[{"count":0,"href":"https:\/\/blog.xiunian.wang\/index.php?rest_route=\/wp\/v2\/posts\/636\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.xiunian.wang\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=636"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.xiunian.wang\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=636"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.xiunian.wang\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=636"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}