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的實時文件夾 個人覺得掌握起來也容易,但是用到的可能性很小。 參考網址:/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);
}
}
摘自 單曲循環