在查看其中ContentProviders
大多数示例时,都包含一个BaseColumns
界面。在比较不同的实现时,每个实现都有不同数量的内部方法。什么是最好放在BaseColumns
界面中的东西,什么是你不应该放进去的?
接口示例BaseColumns
:
public static interface LentItems extends BaseColumns {
public static final Uri CONTENT_URI = LentItemsProvider.CONTENT_URI;
public static final String NAME = "name";
public static final String CATEGORY = "category";
public static final String BORROWER = "borrower";
public static final String CONTENT_PATH = "items";
public static final String CONTENT_TYPE = ContentResolver.CURSOR_DIR_BASE_TYPE + "/vnd.cpsample.lentitems";
public static final String CONTENT_ITEM_TYPE = ContentResolver.CURSOR_ITEM_BASE_TYPE + "/vnd.cpsample.lentitems";
public static final String[] PROJECTION_ALL = {_ID, NAME, CATEGORY, BORROWER};
public static final String SORT_ORDER_DEFAULT = NAME + " ASC";
}
另一个例子
public class Note {
public Note() {
}
public static final class Notes implements BaseColumns {
private Notes() {
}
public static final Uri CONTENT_URI = Uri.parse("content://"
+ NotesContentProvider.AUTHORITY + "/notes");
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.jwei512.notes";
public static final String NOTE_ID = "_id";
public static final String TITLE = "title";
public static final String TEXT = "text";
}
}