自從全球資訊網 Web 被建立以後,文字型的資料處理就一直是程式設計師所必需具備的基本技巧,目前最常見的三種文字處理技術是:
1. 字串物件
2. Regular Expression 比對
3. XML 文件處理.
Android 中的字串相關函式庫
java.lang
java.text
Android.text Provides classes used to render or track text and text spans on the screen.
Android.text.method Provides classes that monitor or modify keypad input.
Android.text.style Provides classes used to view or change the style of a span of text in a View object.
android.text.util
正規表示式
java.util.regex
處理XML 文件
android.sax
javax.xml.parsers
org.json
org.w3c.dom
org.xml.sax This package provides the core SAX APIs.
org.xml.sax.ext This package contains interfaces to SAX2 facilities that conformant SAX drivers won't necessarily support.
org.xml.sax.helpers This package contains "helper" classes, including support for bootstrapping SAX-based applications.
資料儲存
共用資料 – SharedPreference
第1節 SharedPreferences
Preference 是 Android 中用來儲存資料最簡單的一種方法,我們可以使用 :Context.getSharedPreferences() 或 Activity.getPreferences() 取得儲存的變數,或對某一 Preference變數的 editor 物件進行 put 動作以儲存資料,但這些共用資料只能在同一個 Package 底下使用。
以下是使用 Preference 來設定一個小計算機中按鍵模式keypress 的範例程式:
public class Calc extends Activity {
public static final String PREFS_NAME = "MyPrefsFile";
...
@Override
protected void onCreate(Bundle state){
super.onCreate(state);
...
// Restore preferences
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
boolean silent = settings.getBoolean("silentMode", false);
setSilent(silent);
}
@Override
protected void onStop(){
super.onStop();
// Save user preferences. We need an Editor object to
// make changes. All objects are from android.context.Context
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean("silentMode", mSilentMode);
// Don't forget to commit your edits!!!
editor.commit();
}
}
檔案系統 - Files
第2節 Files
Context.openFileOutput() and Context.openFileInput()
If you have static files to package with your application at compile time, you can save your file in your project in res/raw/<mydatafile>, and then get it with Resources.openRawResource (R.raw.mydatafile).
資料庫- Sqlite
第3節 Sqlite
To create a database, use Context.createDatabase() and Context.openDatabase(), and read and write this data as appropriate.
資料提供者 – ContentProvider
第4節 Content Provider
Android 中要跨越應用存取資料,Content Provider 是唯一的方法,Content Provider 是可以被所有應用存取得一種物件。
推薦給同仁
您想要瞭解更多的免費小竅門以便提升你的網站排名嗎?
請馬上聯繫我們網站管理員:
MSN: chenlinwu@cmmail.com
Email: info@rank-ad.com