Baidu locates and obtains county weather-xml+fragment+sqlite

Source: Internet
Author: User
Tags stub

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.