This project is compared with baidulocationxmlfragment:
1. Join the database section, will get the address of the weather into the database, offline status to display the last record of the database
Sqlite:
Databasehelper.java
ImportAndroid.content.Context;Importandroid.database.sqlite.SQLiteDatabase;ImportAndroid.database.sqlite.SQLiteOpenHelper; Public classDatabasehelperextendsSqliteopenhelper {Private Static FinalString db_name = "Weatherdb.db"; Private Static Final intVersion = 1; Public Static FinalString table_name = "Weatherinfo"; PublicDatabasehelper (Context context) {Super(Context, Db_name,NULL, version); //TODO auto-generated Constructor stub} @Override Public voidonCreate (Sqlitedatabase db) {Db.execsql ("CREATE TABLE IF not EXISTS" +table_name+ "(RecordID INTEGER PRIMARY key,address varchar,weather VARCHAR)"); } @Override Public voidOnupgrade (Sqlitedatabase db,intOldversion,intnewversion) { //TODO auto-generated Method Stub }}
Dbmanger.java
//http://blog.csdn.net/liuhe688/article/details/6715983 Public classdbmanager{PrivateDatabasehelper Helper; PrivateSqlitedatabase DB; PublicDBManager (Context context) {LOG.D ("SQLite", "DBManager--Constructor"); Helper=NewDatabasehelper (context); DB=helper.getwritabledatabase (); } /*** Add weatherinfo * *@paramWibs can also be designed as Weatherinfobean object **/ Public voidAdd (list<weatherinfobean>wibs) {LOG.D ("SQLite", "DBManager-to-add"); Db.begintransaction (); Try { for(Weatherinfobean wib:wibs) {db.execsql ("INSERT into" +Databasehelper.table_name+ "VALUES (?,?,?)",NewObject[] {NULL, Wib.getaddr (), Wib.getweather ()}); } db.settransactionsuccessful (); } finally{db.endtransaction (); } } /*** Query all Weatherinfo, return list * *@returnlist<person>*/ PublicList<weatherinfobean>query () {LOG.D ("SQLite", "DBManager-to-query"); ArrayList<WeatherInfoBean> wibs =NewArraylist<weatherinfobean>(); Cursor C=querythecursor (); while(C.movetonext ()) {Weatherinfobean Wib=NewWeatherinfobean (); Wib.setaddr (c.getstring (C.getcolumnindex ("Address"))); Wib.setweather (c.getstring (C.getcolumnindex ("Weather"))); Wibs.add (WIB); } c.close (); returnWibs; } /*** Query All persons, return cursor * *@returnCursor*/ PublicCursor querythecursor () {LOG.D ("SQLite", "DBManager--Querythecursor"); Cursor C= Db.rawquery ("SELECT * from" +Databasehelper.table_name,NULL); LOG.I ("SQLite", "xxxxxxxxx"); returnC; }//Query The last record returns an object PublicWeatherinfobean Querycertainitem () {Weatherinfobean WIB=NewWeatherinfobean (); Db.begintransaction (); Try{cursor cursor= Db.rawquery ("SELECT * from" +Databasehelper.table_name,NULL); if(Cursor.movetolast ()) {//the cursor is the last piece of datawib.setaddr (cursor.getstring (Cursor.getcolumnindex ("Address"))); Wib.setweather (cursor.getstring (Cursor.getcolumnindex ("Weather"))); } } finally{db.endtransaction (); } returnWIB; } /*** Close Database*/ Public voidClosedb () {LOG.D ("SQLite", "DBManager--Closedb"); Db.close (); }}
Source: http://download.csdn.net/detail/xiejun1026/8444571
Baidu locates and obtains county weather-xml+fragment+sqlite