1、ContentProvider的使用
NotePad.java定義了資料庫中唯一的Notes表的若干欄位及其屬性。Notes表實現了BaseColumns介面,即擁有了_id和_count的屬性。資料庫表的Uri的命名規則一般是:content://**/資料庫名 (**代表provider的authorities)。
NotePadProvider.java繼承自ContentProvider,所以需要實現onCreate()、query()、insert()、delete()、update()和getType()共六個方法。
onCreate方法在ContentProvider初始化的時候,執行相應的語句,如果初始化成功返回true,否則返回false。一般在該方法裡,初始化資料庫擷取DatabaseHelper的對象,所有資料庫表的建立都是在Databasehelper對象的onCreate方法裡執行的。
getType方法的作用是:當使用隱式的Intent調用activity的時候,該方法的傳回值決定了activity是否被選中。隱式調用activity方法
intent.setAction(action);
intent.setData(data);
intent.addCategory(category);
[java]
<intent-filter android:label="@string/resolve_edit">
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.EDIT" />
<action android:name="com.android.notepad.action.EDIT_NOTE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="vnd.android.cursor.item/vnd.google.note" />
</intent-filter>
getType的方法傳回值和mimeType的值對應。
2、android的即時檔案夾 個人覺得掌握起來也容易,但是用到的可能性很小。 參考網址:http://www.bkjia.com/kf/201204/128715.html
3、擴充EditText的LineEditText控制項。注意getLineCount和getLineBounds兩個方法。
[java]
public static class LinedEditText extends EditText {
private Rect mRect;
private Paint mPaint;
// we need this constructor for LayoutInflater
public LinedEditText(Context context, AttributeSet attrs) {
super(context, attrs);
mRect = new Rect();
mPaint = new Paint();
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setColor(0x800000FF);
}
@Override
protected void onDraw(Canvas canvas) {
int count = getLineCount();
Rect r = mRect;
Paint paint = mPaint;
for (int i = 0; i < count; i++) {
int baseline = getLineBounds(i, r);
canvas.drawLine(r.left, baseline + 1, r.right, baseline + 1, paint);
}
super.onDraw(canvas);
}
}
摘自 單曲迴圈