freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

畢業(yè)論文-基于android平臺的天氣軟件開發(fā)(編輯修改稿)

2025-02-09 17:22 本頁面
 

【文章內(nèi)容簡介】 ns[j].length。 n++) { childs[i][sum] = towns[j][n][1]。 // + 010203 + .xml urlBuilder = new StringBuffer(urlPre)。 (towns[j][n][0])。 (.xml)。 webContent = (())。 String[][] code = (webContent)。 cityCode[i][sum] = code[0][1]。 sum = sum + 1。 } } init = init + sum。 urlBuilder = null。 } (中國一共有多少個地方: + init)。 // 這里得到的groups數(shù)組記錄的是得到的34個一級地區(qū)字符串, // childs記錄的是與groups數(shù)組對應的一級地區(qū)對應的市級別的字符串名 int g = 0。 StringBuffer str = new StringBuffer()。 for (int j = 0。 j 。 j++) { for (int k = 0。 k childs[j].length。 k++) { // info[g][0] = childs[j][k]。 (childs[j][k] + ,)。 (childs[j][k])。 g++。 } } File file = new File()。 try { ((), file)。 } catch (Exception e) { ()。 } g = 0。 str = new StringBuffer()。 (g2 ==== + g)。 for (int j = 0。 j 。 j++) { for (int i = 0。 i cityCode[j].length。 i++) { (cityCode[j][i] + ,)。 (cityCode[j][i])。 g++。 } ()。 } File file2 = new File()。 try { ((), file2)。 } catch (Exception e) { ()。 } }遍歷后將得到的數(shù)據(jù)分別存放在 和 。在 中存放的是所有的城市名,城市名之間用“,”分隔,之間也用“,”隔開,在存放的時候,將城市名和城市碼的次序一一對應。寫入函數(shù)如下: public static boolean writeTxtFile(String content, File fileName) throws Exception { RandomAccessFile mm = null。 boolean flag = false。 FileOutputStream o = null。 try { o = new FileOutputStream(fileName)。 ((UTF8))。 ()。 flag = true。 } catch (Exception e) { ()。 } finally { if (mm != null) { ()。 } } return flag。 }這樣,整個數(shù)據(jù)的獲取就完成了,得到的城市名和城市碼分別保存在 和 兩個文件中。 數(shù)據(jù)庫實現(xiàn) 數(shù)據(jù)庫存儲在數(shù)據(jù)庫的設計中將數(shù)據(jù)內(nèi)容設計為兩張表:cities和city,cities用于存儲城市名和城市碼,city用于存儲默認的城市碼。首先來實現(xiàn)cities這張表,也就是將上面獲取數(shù)據(jù)后得到的兩個文件中的內(nèi)容存儲到這張表中來。經(jīng)過分析可以知道,應該先將文件中的內(nèi)容讀入到內(nèi)存中,然后創(chuàng)建表,再把數(shù)據(jù)插入到表中。在前面已經(jīng)說過,在兩個文件存儲的時候,城市名和城市名之間、城市碼和城市碼之間用“,”作為間隔,所以讀入后,應以它作為分隔符來進行解析,解析函數(shù)如下: public static String[] parseCity(String content){ if(content!=null amp。amp。 ().length()!=0){ StringTokenizer st = new StringTokenizer(content, ,)。 String[] it = new String[2564]。 int i = 0。 while(()){ String city = ()。 it[i] = city。 i = i + 1。 } return it。 } return null。 }將兩個文件分別解析后,得到的是兩個字符串數(shù)組,這里需要注意的是,兩個數(shù)組中的城市名和城市碼之間是一一對應的。所以接下來要將它們組合起來,得到一個二維數(shù)組,一個城市名對應一個城市碼,共2564個城市,代碼如下: public static String[][] range(String[] city, String[] code){ String[][] str = new String[2564][2]。 for (int i = 0。 i 。 i++) { str[i][0] = code[i]。 str[i][1] = city[i]。 } return str。 }這樣,就得到了一個包含著城市名和城市碼的二維數(shù)組,然后就是創(chuàng)建數(shù)據(jù)庫,創(chuàng)建表,將數(shù)據(jù)插入到表中。在SQLite中對數(shù)據(jù)庫操作要首先獲得一個 SQLiteOpenHelper 對象,但是這個類是一個抽象類,需要創(chuàng)建一個類去實現(xiàn)它,然后繼承它的方法,這里給出一個簡單的實現(xiàn)類:public class DatabaseHelper extends SQLiteOpenHelper { private static final int VERSION = 1。 public DatabaseHelper(Context context, String name, CursorFactory factory, int version) { super(context, name, factory, version)。 } public DatabaseHelper(Context context, String name, int version){ this(context, name, null, version)。 } public DatabaseHelper(Context context, String name){ this(context, name, VERSION)。 } public void onCreate(SQLiteDatabase db) { } public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { }}繼承后要實現(xiàn)的有 onCreate 和 onUpgrade 兩個方法。得到SQLiteOpenHelper 對象后就可以創(chuàng)建數(shù)據(jù)庫了。這里介紹兩個方法: getReadableDatabase 和getWritableDatabase ,由字面意思我們就可以理解他們的含義:獲得一個可讀的數(shù)據(jù)庫和獲得一個可寫的數(shù)據(jù)庫。針對不同的操作選用不同的方法,當數(shù)據(jù)庫不存在的時候,直接創(chuàng)建這個數(shù)據(jù)庫。所以,要創(chuàng)建一個數(shù)據(jù)庫的時候直接調(diào)用它們即可,代碼如下: class CreateDatabaseListener implements OnClickListener { public void onClick(View arg0) { DatabaseHelper dbHelper = new DatabaseHelper(, panda_weather)。 ()。 } }創(chuàng)建的過程是在一個監(jiān)聽器里實現(xiàn)的,這里不再過多介紹。有了數(shù)據(jù)庫就該創(chuàng)建表了,語句如下:(create table cities(_id int, code varchar(10), city varchar(10))。接下來是插入數(shù)據(jù)。在上面已經(jīng)將要插入的數(shù)據(jù)存入到了一個二維數(shù)組中,在插入的時候考慮到亂碼問題,特別設置了編碼方式為 UTF8 編碼,然后逐條插入,代碼如下: class InsertListener implements OnClickListener { public void onClick(View v) { DatabaseHelper dbHelper = new DatabaseHelper(, panda_weather)。 SQLiteDatabase db = ()。 String d1 = 。 String d2 = 。 for (int i = 0。 i 。 i++) { d1 = str[i][0]。 d2 = str[i][1]。 String sql = INSERT INTO cities(_id, code, city) values( + (i+1) + ,?,?)。 ()。 try { (sql, new String[] {new String((),UTF8), new String((), UTF8)})。 } catch (Exception e) { ()。 } ()。 ()。 } (insert ========= OK )。 }}當控制臺顯示最后一句話的時候,就表示所有數(shù)據(jù)插入成功了,一共2564條數(shù)據(jù)。接下來要進行的是創(chuàng)建 city 表,然后插入數(shù)據(jù),這里將默認的城市設置為北京,城市碼是 101010100 。詳細過程不再描述,只給出執(zhí)行語句: (create table city(_id int, code varchar(10))。 String sql = INSERT INTO city(_id, code) values(1, 39。10101010039。)。到這里,整個數(shù)據(jù)庫就創(chuàng)建完成了。數(shù)據(jù)庫名為 panda_weather ,創(chuàng)建的兩張表為 cities 和 city 。接下來檢驗數(shù)據(jù)庫創(chuàng)建是否成功,把虛擬設備運行起來,進入到命令行提示符下,輸入 adb shell 命令,進入到Android操作系統(tǒng)中,通過 cd 命令進入到存放數(shù)據(jù)庫的目錄,輸入命令 sqlite3 panda_weather 后,進入到數(shù)據(jù)庫模式下,然后輸入 .schema 命令,查看數(shù)據(jù)庫中是否包含 cityes 和 city 兩張表,再用 select * from cities。 和 select * from city。 兩條命令查看表中的記錄是否正確。這里,看到的結(jié)果與插入的一致,表示數(shù)據(jù)庫創(chuàng)建成功了。 數(shù)據(jù)庫操作數(shù)據(jù)庫創(chuàng)建成功后,就投入到具體的使用了。經(jīng)過分析可以知道,對數(shù)據(jù)庫的操作主要包括數(shù)據(jù)庫的初始化、由城市名得到對應的城市碼、設置默認城市碼和得到默認城市碼這樣四個操作。代碼如下:public class Database_Tools { // 當前上下文 private Context _context。 // 構造函數(shù) public Database_Tools(Context context) { _context = context。 } private String dbPath = data/data/。 // 數(shù)據(jù)庫路徑 private String dbName = panda_weather。 // 數(shù)據(jù)庫名稱 /** * 把數(shù)據(jù)庫文件復制到指定目錄 */ public void init() { try { String DATABASE = dbPath + dbName。 File dir = new File(dbPath)。 // 如果目錄已經(jīng)存在,則返回 if (()) { return。 } // 創(chuàng)建目錄 ()。 // 如果數(shù)據(jù)庫文件不存在,執(zhí)行復制數(shù)據(jù)庫文件 if (!(new File(DATABASE).exists())) { // 獲得封裝 文件的InputStream對象 InputStream is = ().open(panda_weather)。 FileOutputStream fos = new FileOutputStream(DATABASE)。 // 下面這一段代碼不是很理解,有待研究 byte[] buffer = new byte[8192]。 int count = 0。 // 開始復制db文件 while ((count = (buffer)) 0) { (buffer, 0, count)。 } ()。 ()。 } } catch (Exception e
點擊復制文檔內(nèi)容
教學教案相關推薦
文庫吧 www.dybbs8.com
備案圖片鄂ICP備17016276號-1